skip to Main Content

I’d like to implement a "Reset password" button in the settings of my app but I think I should enable it only for users authenticated with Email and password, and not for users logged with Google.

How could I check the authentication method? Because I could put an If statement and show the button only if the user is logged with email and password I think

2

Answers


  1. You could use,

    FirebaseAuth.instance.currentUser.providerData
    

    To get the specific provider of the user’s authentication.
    Read more here

    Login or Signup to reply.
  2. Either store it in database how the given user logged in or you can use https://pub.dev/packages/shared_preferences to store a value.

    enum LoginType {
      EMAIL, GOOGLE
    }
    
    main() {
       final prefs = await SharedPreferences.getInstance();
    
       if (userLoggedInWithEmail()) {
          await prefs.setString('USER_LOGGED_IN_WITH', LoginType.EMAIL.toString());
       } else {
          await prefs.setString('USER_LOGGED_IN_WITH', LoginType.GOOGLE.toString());
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search