Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Signin anonymous on web and native. #410

Open
1 of 8 tasks
devsuperfrete opened this issue Jul 21, 2023 · 15 comments
Open
1 of 8 tasks

feat: Signin anonymous on web and native. #410

devsuperfrete opened this issue Jul 21, 2023 · 15 comments

Comments

@devsuperfrete
Copy link

Plugin(s)

  • Analytics
  • App
  • App Check
  • Authentication
  • Crashlytics
  • Cloud Messaging
  • Performance
  • Remote Config

Current problem

I'm using the anonymous authentication to autenticate new users on my app, but I need to autenticate this same users on native layer.
My problem is that the signInAnonymously method don't returns a valid credential and the plugin don't expose the method signInWithCredential to I authenticate the user from web to native.

Preferred solution

I need that the method signInAnonymously returns a valid credential OR the method signInWithCredential exposed to the web layer.

Alternative options

No response

Additional context

No response

@robingenz
Copy link
Member

Sorry, I need more context. I don't quite understand your use case. What are you trying to achieve?

@devsuperfrete
Copy link
Author

I'm trying to do one of the following codes above:

    //Use web 
    const credential = await signInAnonymously(auth)
    await FirebaseAuthentication.signInWithCredential({}, credential);

OR

    //Use Native 
   const result = await FirebaseAuthentication.signInAnonymously();
   const auth = getAuth();
   await signInWithCredential(auth, result.credential);

But the method signInWithCredential is not exposed to the web and the method signInAnonymously don't return a valid redential.

We need to authenticate the same anonymous user on the web and native, because our anonymous users need to receive pushs and inapp messages configured with target groups.

Thanks.

@robingenz
Copy link
Member

We need to authenticate the same anonymous user on the web and native, because our anonymous users need to receive pushs and inapp messages configured with target groups.

I haven't tested it but as far as I know you can't authenticate the same anonymous user natively and on the web. This is because no credentials object is returned by Firebase. This can't be changed by this plugin. But that should not be necessary. Push notifications and Inapp messages do not require a native user.

@devsuperfrete
Copy link
Author

devsuperfrete commented Jul 23, 2023

When you autheticate the user as anonymous, the Web layer returns a credential object.

And to use the target audience resource of the firebase we need that the native layer are autheticated with the same anonymous user of the web layer.

@robingenz
Copy link
Member

Okay then, I'll have to take a closer look.
Just out of interest: What Capacitor Firebase plugins are you missing in order to avoid using the Firebase JS SDK on Android and iOS?

@bojanbizjak
Copy link

In our case, it's the storage plugin

@devsuperfrete
Copy link
Author

devsuperfrete commented Jul 25, 2023

Okay then, I'll have to take a closer look. Just out of interest: What Capacitor Firebase plugins are you missing in order to avoid using the Firebase JS SDK on Android and iOS?

I am using the Firebase JS SDK for Android and iOS.

However, the Firebase audience targeting feature only works if the anonymous user is also authenticated natively.

And why is that?

Because each user, whether anonymous or logged in, has their properties well-defined, such as the application version, platform, usage statistics for each feature of our app, and so on. With these properties, we can create target audiences and thus send specific messages to each group of users. However, this only works if the same anonymous user who is authenticated in the JS SDK is also authenticated in the native layer.

In our case, we don't feel the need for any plugin.

@robingenz
Copy link
Member

Okay then, I'll have to take a closer look. Just out of interest: What Capacitor Firebase plugins are you missing in order to avoid using the Firebase JS SDK on Android and iOS?

I am using the Firebase JS SDK for Android and iOS.

However, the Firebase audience targeting feature only works if the anonymous user is also authenticated natively.

And why is that?

Because each user, whether anonymous or logged in, has their properties well-defined, such as the application version, platform, usage statistics for each feature of our app, and so on. With these properties, we can create target audiences and thus send specific messages to each group of users. However, this only works if the same anonymous user who is authenticated in the JS SDK is also authenticated in the native layer.

In our case, we don't feel the need for any plugin.

No, I mean what Firebase products besides Authentication do you use in your app?

@devsuperfrete
Copy link
Author

devsuperfrete commented Jul 25, 2023

No, I mean what Firebase products besides Authentication do you use in your app?

  • Realtime Database
  • Firestore
  • Functions
  • Messaging (Push/Inapp)
  • Remote config
  • Storage
  • Crashlytics
  • Analytics
  • Performance

@robingenz
Copy link
Member

Thank you, that is of course quite a lot. I'm always interested to see which products actually end up being used.

@LirycMoaners
Copy link

Is this issue still up for a fix?

I'm having a similar issue where I automatically logged in my users anonymously and then they can choose to link their account to Google provider.
If I'm using the Firebase SDK to log in anonymously, I can see that I'm connected in my app but not natively and when I try to link natively to Google provider, it's not possible because natively I'm not connected to an account.
If I choose to natively log in anonymously, I can link natively to Google provider but the problem is I can't see my user anonymously connected in my app before linking to Google ...

@robingenz
Copy link
Member

Yes, this issue still on my to-do list. PRs are welcome.

@LirycMoaners
Copy link

I tried different solutions working on a PR but I always reach a dead end.
But I got my problem solved. I stopped using the Firebase SDK and I stopped trying to link your auth system with the one from Firebase SDK.
Now I'm using capacitor-firebase for everything: Authentication, Firestore, Storage, Analytics, Crashlytics and Performance.
It works perfectly now and I even reduced the size of my app using your complete suite of packages.
Thank you for your hard work on those packages, you did a pretty good job!

@ianitsky
Copy link

Is this issue still up for a fix?

I'm having a similar issue where I automatically logged in my users anonymously and then they can choose to link their account to Google provider. If I'm using the Firebase SDK to log in anonymously, I can see that I'm connected in my app but not natively and when I try to link natively to Google provider, it's not possible because natively I'm not connected to an account. If I choose to natively log in anonymously, I can link natively to Google provider but the problem is I can't see my user anonymously connected in my app before linking to Google ...

@LirycMoaners You can create a firebase function for create a custom token for the loggedin user, with firebase admin sdk.
After login on web, you call this function and with the token make a loginWithCustomToken call on native layer.
This is not the best solution. I'm waiting for a better way, but this solution works for now.

@LirycMoaners
Copy link

Thank you for your reply.
Yes definitely not the best solution in terms of cost and performances (as the function has to wake up before doing something).
But it still is a way of doing it.
As I said, I completely stopped trying to link with the JavaScript SDK and now I'm using only capacitor-firebase modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants