question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying the Auth state persistence returns Type Error "Cannot read property 'Persistence' of undefined"

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
nicolasgarniercommented, Nov 28, 2017

This should work:

import firebase from 'firebase/app';
import 'firebase/auth';

console.log(firebase.auth.Auth.Persistence.SESSION);

app.auth.Auth won’t work, normally you should do firebase.auth.Auth

0reactions
nicolasgarniercommented, Aug 31, 2018

Closing for inactivity.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found