How constant is the Firebase Anonymous ID

我怕爱的太早我们不能终老 提交于 2020-08-01 07:05:55

问题


I'm building an app with Firebase Real-Time Database. The app will be mainly offline at first, but we are planning an online update later. I'm planning to use the anonymous sign in, to get an ID for the user and store all his data under this ID:

Auth.auth().signInAnonymously(completion: { (user, error) -> Void })

After signing in I get an ID that looks like something like this: pCfgFOvEYEYvfWHaaaaavKgs8h33

Is it guaranteed that this ID will ALWAYS stay unchanged on a given device? I couldn't find any documentation about this.


回答1:


A user's UID never changes. So after you sign in a user anonymously, the UID will remain the same until you call signInAnonymously again or until you call signout.




回答2:


You should check this out:

Firebase also allows for anonymous auth sessions, which are typically used to persist small amounts of data while waiting for a client to authenticate with a permanent auth method. These anonymous sessions can be configured to last days, weeks, months, even years… until the user logs in with a permanent login method or clears her browser cache. Web apps often use local datastores like sessionStorage or localStorage to accomplish similar tasks.

It is not guaranteed that the ID will always stay unchanged on a given device. Firebase stores the anonymous auth sessions to browser's localStorage. If users open your application in incognito mode / private browsing mode, another browsers, or they clear their browser's localStorage, firebase will issue another user ID.




回答3:


If you login anonymous then your UID will remain unchanged until you logout. Once you logged out, and log in again, you will get a new UID. Or even when the user uninstalls the app, you will get UID again.




回答4:


Here's what I've found using Flutter:

  • if you call FirebaseAuth.signInAnonymously() twice without calling FirebaseAuth.signOut() in between, you get the same uid (from AuthResult.user.uid) as the first call. This is true even if you close the app and call FirebaseAuth.signInAnonymously()
  • if you call FirebaseAuth.signOut() and then call FirebaseAuth.signInAnonymously(), you get a new uid
  • if you uninstall the app and call FirebaseAuth.signInAnonymously(), you get a different uid from the previous install

Is summary, you get a new uid if you call signInAnonymously() after signOut() or after uninstalling the app.



来源:https://stackoverflow.com/questions/47854428/how-constant-is-the-firebase-anonymous-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!