![](/img/trans.png)
[英]Firebase functions.auth.user().onCreate no triggering
[英]Can Firebase Auth.auth() functions be used to retrieve a GoogleSignIn user?
在我的應用程序中,我有兩種身份驗證:
這是在用戶使用其 email 地址進行身份驗證時創建用戶的相關代碼:
// Create the user
Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
// Check for errors
if err != nil {
// There was an error creating the user
self.showError("Error creating user")
}
else {
// User was created successfully, now store the first name and last name
UserService.createProfile(userId: Auth.auth().currentUser!.uid, firstName: firstName, lastName: lastName, email: email) { (user) in
}
}
}
對於使用 email 地址進行身份驗證的用戶,我已經能夠在我的應用程序中為他們成功調用多個函數。 例如:
let currentUser = Auth.auth().currentUser?.uid
Auth.auth().addStateDidChangeListener { (auth, user) in }
這是我的AppDelegate
中用於使用 Google 登錄用戶的內容: func sign(_ signIn: GIDSignIn,: didSignInFor user, GIDGoogleUser:, withError error: Error!) {}
有沒有辦法為谷歌認證的用戶使用那些現有的Auth.auth()
函數? 或者我是否需要在我的整個應用程序中添加新代碼來說明這些用戶?
我不確定我是否理解,但會嘗試回答最有可能的問題。
如果您想將經過 Google 身份驗證的用戶登錄到 Firebase,您可以通過調用Auth.auth().signIn(with: credential)
來完成此操作,如在使用 Google 登錄后使用 Firebase 進行身份驗證的文檔中所示。
一旦用戶使用 Firebase 身份驗證登錄(無論使用什么提供商), auth.currentUser
將為他們設置(並在他們退出 Firebase 時清除), addStateDidChangeListener
將為他們觸發事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.