firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.83k stars 891 forks source link

Firestore v9 sign in with email and password alerts worng password even the password is correct #7109

Closed urlsab closed 1 year ago

urlsab commented 1 year ago

The login works only for the first time after you just create a new account, but when you logout - firestore forget the password or see that as null

on consloe i get: auth/wrong-password Firebase: Error (auth/wrong-password).

And here my code: [consider all imports etc]

    const onLogin = async (e) => { 

   e.preventDefault();

    await signInWithEmailAndPassword(curAuth, email, password)

    .then((userCredential) => {
        const user = userCredential.user;
        console.log(user);
        console.log(curAuth);
        console.log(password);
        navigate("/dashboard");    
    })

    .catch((error) => {
        const errorCode = error.code;
        const errorMessage = error.message;
        console.log(errorCode, errorMessage);
        console.log(curAuth);
        // alert(errorCode);
    });

}
hsubox76 commented 1 year ago

I see you have a console.log for the password only after a successful login. For debugging, I would suggest logging the email and password strings before creating the account (before createUserWithEmailAndPassword), and then again before signing in (before signInWithEmailAndPassword), just to make sure there isn't some error in your code processing the string that causes it to be empty or null before you pass it to the Firebase auth functions.

urlsab commented 1 year ago

ok I'll do it

urlsab commented 1 year ago

So - I logged both of them and I do get string of the currect password but only first login is working , right after creating new user. But when I'm trying to login again (after logout) - firestore forgetting my password or my account.

Here's the full description:

const onSubmitHandler = async (e) => {

        e.preventDefault();

        console.log(curAuth, emailAdd, rePassword);

        await createUserWithEmailAndPassword(curAuth, emailAdd, rePassword)

        .then((userCredential) => {
            let userData = userCredential.user;
            userData.displayName = rePassword;
            userData.phoneNumber = firstName;

            console.log(auth);
            console.log(userData)
            console.log(`the user password is: ${rePassword} `);
            console.log(`displayName:${userData.displayName}`);
            console.log(`phoneNumber:${userData.phoneNumber}`);
        })

        .catch((error) => {
            const errorCode = error.code;
            const errorMessage = error.message;
            console.log(errorCode, errorMessage);
            console.log("error from createUserWithEmailAndPassword function")
        })

the logs before create user method:

AuthImpl {app: FirebaseAppImpl, heartbeatServiceProvider: Provider, config: {…}, currentUser: UserImpl, emulatorConfig: null, …} 'yairsabag213@gmail.com' 'mama1234'

[mama1234 is the correct password !]


const onLogin = async (e) => {

        e.preventDefault();

        console.log(curAuth, email, password);

        await signInWithEmailAndPassword(curAuth, email, password)

        .then((userCredential) => {
            const user = userCredential.user;
            console.log(user);
            console.log(curAuth);
            console.log(password);
            navigate("/dashboard");    
        })

        .catch((error) => {
            const errorCode = error.code;
            const errorMessage = error.message;
            console.log(errorCode, errorMessage);
            console.log(curAuth);
            // alert(errorCode);
        });

    }

when I first time create the user , the login is working. But when I logout and try to login in again with password - it's not working !


the logs for fisrt time login after create new user and befor the method signin:

AuthImpl {app: FirebaseAppImpl, heartbeatServiceProvider: Provider, config: {…}, currentUser: UserImpl, emulatorConfig: null, …} 'yairsabag213@gmail.com' 'mama1234'


the logs for login after logout and try login second time - before the method sign in:

AuthImpl {app: FirebaseAppImpl, heartbeatServiceProvider: Provider, config: {…}, currentUser: null, emulatorConfig: null, …} 'yairsabag213@gmail.com' 'mama1234'


the logs after signin method:

  1. POST https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8 400 (Bad Request)

  2. auth/wrong-password Firebase: Error (auth/wrong-password).

  3. AuthImpl {app: FirebaseAppImpl, heartbeatServiceProvider: Provider, config: {…}, currentUser: null, emulatorConfig: null, …} app : FirebaseAppImpl {_isDeleted: false, _options: {…}, _config: {…}, _name: '[DEFAULT]', _automaticDataCollectionEnabled: false, …} authStateSubscription : Subscription {auth: AuthImpl, observer: ObserverProxy, addObserver: ƒ} beforeStateQueue : AuthMiddlewareQueue {auth: AuthImpl, queue: Array(0)} clientVersion : "Chrome/JsCore/9.17.1/FirebaseCore-web" config : {apiKey: 'AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8', authDomain: 'resumes-builder.firebaseapp.com', clientPlatform: 'Browser', apiHost: 'identitytoolkit.googleapis.com', tokenApiHost: 'securetoken.googleapis.com', …} currentUser : null emulatorConfig : null frameworks : [] heartbeatServiceProvider : Provider {name: 'heartbeat', container: ComponentContainer, component: Component, instances: Map(1), instancesDeferred: Map(0), …} idTokenSubscription : Subscription {auth: AuthImpl, observer: ObserverProxy, addObserver: ƒ} isProactiveRefreshEnabled : true languageCode : null lastNotifiedUid : null name : "[DEFAULT]" operations : Promise {: undefined} persistenceManager : PersistenceUserManager {persistence: IndexedDBLocalPersistence, auth: AuthImpl, userKey: 'authUser', fullUserKey: 'firebase:authUser:AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8:[DEFAULT]', fullPersistenceKey: 'firebase:persistence:AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8:[DEFAULT]', …} redirectPersistenceManager : PersistenceUserManager {persistence: BrowserSessionPersistence, auth: AuthImpl, userKey: 'redirectUser', fullUserKey: 'firebase:redirectUser:AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8:[DEFAULT]', fullPersistenceKey: 'firebase:persistence:AIzaSyCEryolwTvi751-v2evqPUquUvlcugNys8:[DEFAULT]', …} redirectUser : null settings : {appVerificationDisabledForTesting: false} tenantId : null _canInitEmulator : false _deleted : false _errorFactory : ErrorFactory {service: 'auth', serviceName: 'Firebase', errors: {…}} _initializationPromise : Promise {: undefined} _isInitialized : true _popupRedirectResolver : BrowserPopupRedirectResolver {eventManagers: {…}, iframes: {…}, originValidationPromises: {…}, _redirectPersistence: ƒ, _completeRedirectFn: ƒ, …} assertedPersistence : PersistenceUserManager _currentUser : null [[Prototype]] : Object

urlsab commented 1 year ago

I think i found the answer.

https://github.com/firebase/firebaseui-web/issues/122

Don't sign in firestore auth if your google accouny t is connected.

I tried another email/google account I know, that is not connected to my pc - and i succeeded login and time.

malcolmdeck commented 1 year ago

I'm glad you were able to resolve this issue on your own :)

urlsab commented 1 year ago

Thanks

בתאריך יום ב׳, 13 במרץ 2023, 19:18, מאת Malcolm Deck ‏< @.***>:

I'm glad you were able to resolve this issue on your own :)

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-js-sdk/issues/7109#issuecomment-1466573893, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASLT576XSHASZGK3FE6M5KLW35JF5ANCNFSM6AAAAAAVU5UYSM . You are receiving this because you authored the thread.Message ID: @.***>