Skip to content

Instantly share code, notes, and snippets.

@lunhg
Last active July 11, 2017 17:34
Show Gist options
  • Save lunhg/34b155447518060f6b2fbc846d0f5d97 to your computer and use it in GitHub Desktop.
Save lunhg/34b155447518060f6b2fbc846d0f5d97 to your computer and use it in GitHub Desktop.
Given a firebase, and populated users, you can start a login request creating a custom token for that access, and then checkout it on client side with web SDK
passport = require('passport')
passport_custom = require('passport-custom')
getAuth = (req) -> new Promise (resolve, reject) -> resolve req.query['email']
passport.use 'firebase-admin-login', new passport_custom (req, done) ->
onErr = (error) ->
console.log error
done error.code, null, message: error.message
onUser = (userRecord) ->
uid = userRecord.toJSON().uid
firebase_admin.auth()
.createCustomToken(uid)
.then (customToken) ->
console.log customToken
done null, uid, customToken: customToken
.catch onErr
getAuth(req).then (email) ->
firebase_admin.auth()
.getUserByEmail(email)
.then onUser
.catch onErr
.catch onErr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment