简体   繁体   English

Flutter Firebase 登录 function

[英]Flutter Firebase login function

How to access if users exist on users/$usersUids[index]如果用户存在于 users/$usersUids[index] 上,如何访问

_db.collection('users').doc(user1.uid).set({
    "displayName": user1.displayName,
    "email": user1.email,
    "uid": user1.uid,
    'date': date,
    "photoUrl": user1.photoURL,
    "lastSignIn": DateTime.now(), 
  });

or if the user has already login/signup then I want to run或者如果用户已经登录/注册,那么我想运行

_db.collection('users').doc(user1.uid).set({
    "displayName": user1.displayName,
    "email": user1.email,
    "uid": user1.uid,
    'date': date,
    "photoUrl": user1.photoURL,
    "lastSignIn": DateTime.now(),
    'favItems': []
  });

If the question is wrong then please fix this Thank you如果问题是错误的,那么请解决这个问题谢谢

You can use firebase authentication to see if the user is logged in, you will need to set that up in your Firebase Console .您可以使用 firebase 身份验证来查看用户是否已登录,您需要在Firebase 控制台中进行设置。 Here's a video I used to help me set it up: Flutter Authentication with Email and Password Tutorial Below is an example of what your code may look like once you have the authentication set up.这是我用来帮助我设置它的视频: Flutter 使用 Email 和密码教程进行身份验证下面是一个示例,说明设置了身份验证后您的代码可能会是什么样子。

import 'package:firebase_auth/firebase_auth.dart';

FirebaseAuth auth = FirebaseAuth.instance;
    User? user = auth.currentUser;

    // CHECK LOGIN STATUS OF USER AND DECIDE WHICH SCREEN TO SHOW USER
    // ignore: unnecessary_null_comparison
    if (user != null) {
      // SHOW THE USERS PERSONAL HOME PAGE
      currentScreen = 1;
    } else {
      // USER IS NOT LOGGED IN, SHOW THE SIGN IN SCREEN
      currentScreen = 2;
    }

Let me know if I need to clarify anything else for you.让我知道是否需要为您澄清其他任何事情。

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

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