[英]What is the best way to check if the user is new in firebase google sign in with flutter
我想在 Flutter 中使用谷歌登录的新用户登录后添加一些额外的功能。所以我需要知道用户是否是新用户。 如果用户是新用户,那么我想添加一些用户信息。 否则导航到另一个页面。
那么如何检查用户是否是新用户?
User
object有一个metadata
属性,它有两个属性: creationTime
和lastSignInTime
。 当这些间隔不超过几毫秒时,用户才刚刚创建。 如果它们相距较远,则该用户是在之前的 session 中创建的。
FirebaseAuth 用户在 metadata 属性中包含此数据。 我使用了以下代码块。 如果需要,您可以更改秒数。
bool isNewUser(User user) {
DateTime now = DateTime.now();
DateTime cTime = user.metadata.creationTime;
int longAgo = 15; // to check account creation under last 15 seconds
return now.difference(cTime).inSeconds > longAgo;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.