我已实现使用Apple登录。我以这种方式启动首次用户:
let credential = OAuthProvider.credential(withProviderID: "apple.com",idToken: idTokenString,rawNonce: nonce)
然后登录用户:
// HERE: Auth.auth().currentUser is always nil for first time users AND returning users
Auth.auth().signIn(with: credential) { (authResult,error) in
// HERE: Auth.auth().currentUser is never nil for first time users AND returning users
if error == nil {
guard let uid = authResult?.user.uid else { return }
let databaseRef = Database.database().reference().child("Users/\(uid)")
//update realtime database here
}
}
对于初次使用的用户来说效果很好。问题是当它是回头用户时。基本上,对于首次使用用户和回头用户,我需要两个不同的操作。区别在于返回用户,我不向数据库添加任何内容
P.S。我遵循了here
中来自firebase的官方文档