Logging in anonymous user with custom token removes the anonymous status

Viewed 153

What is the exact definition of an anonymous user in firebase authentication?

when I call signInAnonymously() obviously the user is isAnonymous: true. But if I create a custom token for the user via the admin sdk and then log in again with that customToken (using signInWithCustomToken(token)) the user is no longer isAnonymous.

Is this a bug or intended? And is there any workaround to persist that anonymous state?

1 Answers

What is the exact definition of an anonymous user in firebase authentication?

It's a user account that doesn't have a person's identity attached to it. It merely recognizes that someone (probably the same person) is using the app over time, on a specific device.

But if I create a custom token for the user via the admin sdk and then log in again with that customToken (using signInWithCustomToken(token)) the user is no longer isAnonymous.

When you sign in a new account, the prior account is always immediately signed out. This is true for all types accounts, and has nothing to do with anonymous auth. There can only be one user signed in at a time.

Is this a bug or intended?

Working as intended.

And is there any workaround to persist that anonymous state?

No, the anonymous account is signed out after you sign in a new account. If you instead want to upgrade that anonymous account with a known identity, you should look into linking a new identity to the existing anonymous account by converting the anonymous account to a permanent account. This will preserve the account, but it will no longer be anonymous (as it now contains some identity information in it).

Related