简体   繁体   English

当前用户 ID 在退出后保持不变 | Firebase 认证 | Flutter Web

[英]Current user id is persistent after signing out | Firebase Auth | Flutter Web

AuthService.dart AuthService.dart

 static Future<void> login(
      BuildContext context, String email, String password) {

try{
UserCredential userCredential = await FirebaseAuth.instance
          .signInWithEmailAndPassword(email: email, password: password);
}catch(e){
print(e);
}

static void signOut(BuildContext context) async {
    await FirebaseAuth.instance.signOut();
  }

}

LoginPage.dart登录页面.dart

ElevatedButton(
                                onPressed: () {
                                  setState(() async{
                                    if (_loginFormKey.currentState!.validate()) {
                                    _loginFormKey.currentState!.save();
                                    await AuthService.login(context, email!, password!);
                                    }
                                  });
                                },
                                style: ButtonStyle(
                                    backgroundColor:
                                        MaterialStateProperty.resolveWith(
                                            (states) => Colours.blk),
                                    shape: MaterialStateProperty.all<
                                            RoundedRectangleBorder>(
                                        RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(30.0),
                                    ))),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Text(
                                      "Log in"
                                    ),
                                  ],
                                ),
                              ),

Whenever i use sign out after successfully signing in, the current user id is persistent which makes it impossible to sign in with different credentials unless you restart the website每当我在成功登录后使用注销时,当前的用户 ID 都是持久的,这使得除非您重新启动网站,否则无法使用不同的凭据登录

Can you try sign out like this您可以尝试像这样退出吗

Future<void> _signOut() async {
  await FirebaseAuth.instance.signOut();
}

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

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