简体   繁体   中英

Firebase Authentication Get User Profile

So on the Firebase Docs, there is this block of code:

let user = Auth.auth().currentUser
if let user = user {
  // The user's ID, unique to the Firebase project.
  // Do NOT use this value to authenticate with your backend server,
  // if you have one. Use getTokenWithCompletion:completion: instead.
  let uid = user.uid
  let email = user.email
  let photoURL = user.photoURL
  // ...
}

I don't understand how to use this. I'm trying to use this when a user logs in. Can someone help explain this?

The currentUser call synchronously gets the cached current user, or null if there is none.

Then if the user is not null, you will have access to all of the variables within the user block, via optional unwrapping.

When you create a new user with email and password or using some federated identity providers, the email and user id value will be auto created.

You can use a uid to reference a user within database solutions like Firestore or Realtime database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM