I'm building a website for my project where I want to use Google auth by Firebase. I'm implemented a sign in method:
Future<User?> signInWithGoogle() async {
User? user;
GoogleAuthProvider authProvider = GoogleAuthProvider();
try {
final UserCredential userCredential =
await auth.signInWithPopup(authProvider);
user = userCredential.user;
} catch (e) {
print(e);
}
if (user != null) {
name = user.displayName;
imageUrl = user.photoURL;
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool('auth', true);
}
return user;
}
My first question: Is this a good solution? I didn't find any good tutorial for this problem, just the Flutter documentation.Is it a safe solution for a website?
My second question: How can I sign out the user, and how can I detect if a user is signed in?
Aucun commentaire:
Enregistrer un commentaire