Last active
July 11, 2017 17:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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