I am using firebase auth in my swift app, I am saving the logged user firebase uid in UserDefaults so when the user close the app and return if the uid exist in UserDefaults it will get the user's infos from the firebase and if it is nil he will show him the auth viewController. It works like charme but I found that when the app is not opened for a période the firebase disconnect the user and the uid in UserDefaults still found so the app will throw an exception on Auth.auth().currentUser! . So my question is how to keep the user connected to firebase ?

1 Answers

0
Community On

Try this:

// Create a callback which logs the current auth state
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.onAuth(function(authData) {
    if (authData) {
        console.log("User " + authData.uid + " is logged in with " + authData.provider);
    } else {
        console.log("User is logged out");
    }
});

You can also check here: https://www.firebase.com/docs/web/guide/user-auth.html#section-monitoring-authentication