Skip to content

Login persistence lost after upgrading from v8 to v9 #6732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomgiam opened this issue Oct 27, 2022 · 15 comments
Closed

Login persistence lost after upgrading from v8 to v9 #6732

tomgiam opened this issue Oct 27, 2022 · 15 comments

Comments

@tomgiam
Copy link

tomgiam commented Oct 27, 2022

@dconeybe

[REQUIRED] Describe your environment

Windows 10
"firebase": "8.2.3",
"expo": "^46.0.15",
"react-native": "0.69.6",

upgraded firebase to 9.6.11

[REQUIRED] Describe the problem

Steps to reproduce:

I upgraded the firebase version in my expo (react native) app from V8 to V9 (in compatibility mode) and the login persistence feature no longer works. Now the users need to login to the app after every app launch. Previously it remembered unless one explicitly logged off or a new app version was created.

That feature also works the same way on the web version of the app. In both cases the feature worked without me doing anything special. Now I need to know how to get it back in v9 or I may have to go back to v8.

Relevant Code:

old v8 imports:
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";
import "firebase/firestore";
import "firebase/functions";
import "firebase/storage";

new v9 imports:
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/database";
import "firebase/compat/firestore";
import "firebase/compat/functions";
import "firebase/compat/storage";

static Login = (email, password, callback) => {
// try {
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then((res) => {
//console.log(res);
callback({ pass: true, res: res });
})
.catch((error) => {
//console.log(error.message);
callback({ pass: false, res: error });
});
};

The rest of the code is the same except for adding:
db.settings({ experimentalForceLongPolling: true });

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@nlarif
Copy link

nlarif commented Oct 30, 2022

I have exact same issue since upgrading Firebase from v8.2.3 to v9.13.0 (verified with git bisect) : user from onAuthStateChanged is null.
I also use compat version for now, I only changed the imports.

If I try to keep initialization v8 style with compat and use v9 getAuth, new onAuthStateChanged, etc. I get this error :

TypeError: undefined is not an object (evaluating 'app.container.getProvider')

I guess that it should work if I upgrade all the code to v9 including the initialization (that should be the last step of upgrade), but it is a shame to not benefit from the compat libraries to migrate step by step.

PS : after updating the first functions and removing compat from first screens of my App, it works fine with v9. No choice but to update all from now.

@prameshj
Copy link
Contributor

Couple of clarifications:

  1. Is the issue happening on React Native only, or in web apps as well?
  2. Does it fail when using v9 compat, but works with v8 and v9 modular?

@tomgiam
Copy link
Author

tomgiam commented Oct 31, 2022

@prameshj Hi, thanks for looking into this.

  1. I have not upgraded firebase to v9 on my web app yet (using 8.8.1). I could try it and let you know. They use very similar code, since the web version is written in reactjs. In fact the firebase code is exactly the same.
  2. I have not tried v9 modular yet. I upgraded to v9 compat to solve a pressing issue with firebase that was solved by using this setting:

db.settings({ experimentalForceLongPolling: true });

See #6718

@tomgiam
Copy link
Author

tomgiam commented Nov 1, 2022

@prameshj I upgraded my web app to the same version of v9 as the react app (9.6.11) and the login persistence issue is not there, so it seems to be isolated to react native. I only tried it on a windows PC, so to be thorough I should also try running the web app on a mobile device. The javascript code that interacts with firebase is exactly the same for mobile and browser.

I don't have time at the moment to try the v9 modular code in react native. When I do, I will let you know the results. It's not urgent for me because V8 is working fine for me at the moment in react native. However, I do want to migrate to the latest version at some point.

@prameshj
Copy link
Contributor

prameshj commented Nov 1, 2022

Thanks for confirming that it is isolated to React Native. Looks like this might be a dup of #6050

@nlarif
Copy link

nlarif commented Nov 2, 2022

I confirm that I faced the issue with React Native (Expo).
I upgraded all my functions to v9 modular, session is persistent now.
So React Native + v9 compat -> no persistence.
Unfortunately, I was not able to mix v9 compat initializeApp with v9 modular initializeAuth to avoid upgrading everything.

@tomgiam
Copy link
Author

tomgiam commented Nov 2, 2022

@nlarif Thanks for the confirmation. I will upgrade to v9 modular as well.

@skb1129
Copy link

skb1129 commented Jan 19, 2023

I can confirm I am facing this issue in certain Android Google Chrome browsers using the library on a web application

@thesoicalapp91
Copy link

thesoicalapp91 commented Mar 31, 2023

Anyone still having issues with keeping the user logged in after refreshing the app please see my fix and stack overflow link for this:

my issue answered: #7152

stack overflow answer: https://stackoverflow.com/questions/75669669/how-to-persist-firebase-user-auth-on-react-native/75898568#75898568

@jmoussu
Copy link

jmoussu commented May 10, 2023

In React Native with the JS SDK on expo you can =>
import { getAuth, initializeAuth, getReactNativePersistence} from "firebase/auth/react-native"
You can use it like that.
this soluce save me =>

import { getAuth, initializeAuth, getReactNativePersistence} from "firebase/auth/react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";

if (getApps().length === 0) {
app = initializeApp(firebaseConfig);
auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage),
});

} else {
app = getApp();
auth = getAuth(app);
} 

From https://github.com/Scooter1337 => #6050

@DellaBitta
Copy link
Contributor

Hi @tomgiam,
it sounds like this is officially a dup of #6050. Is that correct? Thanks!

@tomgiam
Copy link
Author

tomgiam commented May 29, 2023

@DellaBitta Yes, it seems to be a dupe of #6050. I have not tried the workaround suggested there. I'm still using V8 for now.

@google-oss-bot
Copy link
Contributor

Hey @tomgiam. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Contributor

Since there haven't been any recent updates here, I am going to close this issue.

@tomgiam if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@firebase firebase locked and limited conversation to collaborators Jul 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants