Last active
October 13, 2019 13:46
-
-
Save luandevpro/bc0c8bd306e41136fc7384ece8fbf7c7 to your computer and use it in GitHub Desktop.
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
import withFirebase from '../../../middlewares/withFirebase'; | |
async function handle(req, res) { | |
const token = req.cookies.token || req.headers.authorization.split(' ')[1]; | |
if (token) { | |
req.admin | |
.auth() | |
.verifyIdToken(token) | |
.then((decodedIdToken) => { | |
if (decodedIdToken) { | |
req.admin | |
.auth() | |
.createSessionCookie(token, { expiresIn: 60 * 60 * 24 * 7 * 1000 }) | |
.then((sessionCookie) => { | |
const options = { | |
maxAge: 60 * 60 * 24 * 7 * 1000, | |
domain: 'localhost', | |
httpOnly: true, | |
}; | |
res.cookie('token', sessionCookie, options); | |
res.json({ sessionCookie }); | |
}); | |
} | |
}) | |
.catch(() => { | |
res.status(400).json({ message: 'Not authorized! Go back!' }); | |
}); | |
} else { | |
res.status(400).json({ message: 'Not authorized! Go back!' }); | |
} | |
} | |
export default withFirebase(handle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment