Ad

Passport.deserializeUser() Not Working With Firebase

I'm having trouble searching the user thorough Firebase using the passport.deserializeUser() method.

If I write the code like this

passport.deserializeUser((id, done) => {
   // id has the correct value, Twitter id for example when user tries to log in
     database.child('people').orderByChild('id').equalTo(id).once('value', user => {
     console.log(user.val()); //null
   });
     done(null, user.val());
});

user.val() returns null.

If I write

console.log(user)

user returns an object even if the value is equal or not.

I know that Firebase has it's own Authentication methods in the web console, but I'm wondering why is this not working? The same method for database database.child().orderByChild() works elsewhere but not in passport.deserializeUser().

I've set up the passport.session, cookieParser and cookieSession and the browser does receive the cookie from the server, but when I try to deserialize the user it doesn't work. When I try to authenticate with strategies, it passes through the passport.deserialize() but the Firebase part doesn't work, even though it holds the correct id value.

Ad

Answer

In your code, user is always going to be a DataSnapshot object. The val() method on that object will return null if there is no data at the location that you queried. This is all intended behavior of Realtime Database queries, and has nothing to do with authentication.

Ad
source: stackoverflow.com
Ad