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.
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.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM