Modifying the Auth state persistence returns Type Error "Cannot read property 'Persistence' of undefined"
See original GitHub issueHi there, I’ve read the docs and I want to make it so that the authentication only lasts for until they close the tab or window, and not forever. Right now, closing and re-opening the window still leaves the user logged in.
I’ve tried two solutions: Putting the setPersistence() method in the firebase file:
import Rebase from 're-base'
import firebase from 'firebase'
const facebookProvider = new firebase.auth.FacebookAuthProvider()
const googleProvider = new firebase.auth.GoogleAuthProvider();
var config = {
apiKey: "
authDomain: "t
databaseURL: "
projectId:
storageBucket: "
messagingSenderId:
};
const app = firebase.initializeApp(config)
>>>app.auth().setPersistence(app.auth.Auth.Persistence.SESSION)<<<
const base = Rebase.createClass(app.database())
export { app, base, facebookProvider, googleProvider }
and right at the moment of logging in where the login method is chained as a promise to the setPersistence() method.
app.auth().fetchProvidersForEmail(email)
.then((providers) => {
// if (providers.length === 0) {
// // create user
// return app.auth().createUserWithEmailAndPassword(email, password)
// console.log("made a a new user")
// } else
if (providers.indexOf("password") === -1) {
// they used facebook
this.loginFormReset();
this.changeSnackbarMessage("Hmm... We don't have an account with that email.");
this.handleSnackbarClick();
} else {
>>> firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION) <<<
.then(function() {
app.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
if (errorCode === 'auth/wrong-password') {
alert(':-( Kindly check if your username and password are correct.');
} else {
alert(errorMessage);
}
console.log(error);
// ...
});
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// var errorCode = e.code;
// var errorMessage = e.message;
// this.changeSnackbarMessage("/:/( Kindly check if your username and password are correct.");
// this.handleSnackbarClick();
}
})
Both instances give the error
TypeError: Cannot read property 'Persistence' of undefined
and point to the line: firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
firebase.auth().setPersistence error of 'Persistence' of undefined
Looks like you're trying to get Auth.Persistence from the wrong object. You say this.auth = app.auth() , so i assume then that app...
Read more >Authentication State Persistence | Firebase - Google
Supported types of Auth state persistence; Modifying the Auth state persistence; Overview of persistence behavior; Expected behavior across browser tabs.
Read more >Authentication | React Native Firebase
If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() ...
Read more >AuthSession - Expo Documentation
json, and then build your standalone app (it can't be updated with an update). If you do not include a scheme, the authentication...
Read more >React JWT Authentication (without Redux) example - BezKoder
Hi, if you get the error “TypeError: Cannot read property 'username' of undefined”, your version of express is different. This error means that ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should work:
app.auth.Auth
won’t work, normally you should dofirebase.auth.Auth
Closing for inactivity.