简体   繁体   English

Firebase 首次登录或注册事件

[英]Firebase first login or signup events

I am using firebase authentication in my app.我在我的应用程序中使用 firebase 身份验证。 I want to redirectUser to a particular page if the user signs in for the first time or just signs up.如果用户是第一次登录或刚刚注册,我想将用户重定向到特定页面。 Can somebody please tell me how to do this?有人可以告诉我该怎么做吗?

I you are using a identity provider, such as Google Sign-In or Facebook Login the only way to do that is to store an atributte where you kept the information needed to check if is the first login or not.如果您使用的是身份提供者,例如 Google 登录或 Facebook 登录,唯一的方法是存储一个属性,您可以在其中保存检查是否是第一次登录所需的信息。

If you're using a password based account you can call the function to redirect after creating the user.如果您使用的是基于密码的帐户,则可以在创建用户后调用该函数进行重定向。

firebase.auth()
  .createUserWithEmailAndPassword(email, password)
  .then(() => { 
    //MyFunction
  }).catch((error) => { 
    //Handle the error
  });

Currently, the best way is to use Firebase Authentication Triggers (Cloud functions).目前,最好的方法是使用 Firebase 身份验证触发器(云功能)。

Firebase accounts will trigger user creation events for Cloud Functions when:在以下情况下,Firebase 帐户将触发 Cloud Functions 的用户创建事件:

  • A user creates an email account and password.用户创建电子邮件帐户和密码。
  • A user signs in for the first time using a federated identity provider.用户使用联合身份提供者首次登录。
  • The developer creates an account using the Firebase Admin SDK.开发人员使用 Firebase Admin SDK 创建一个帐户。
  • A user signs into a new anonymous auth session for the first time.用户首次登录到新的匿名身份验证会话。 A Cloud一朵云

Functions event is not triggered when a user signs in for the first time using a custom token.当用户首次使用自定义令牌登录时,不会触发 Functions 事件。

https://firebase.google.com/docs/functions/auth-events#trigger_a_function_on_user_creation https://firebase.google.com/docs/functions/auth-events#trigger_a_function_on_user_creation

Kudos to this (open) issue on Github: https://github.com/firebase/firebaseui-web/issues/137感谢 Github 上的这个(开放的)问题: https ://github.com/firebase/firebaseui-web/issues/137

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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