gcp-express-auth
v1.0.0
Published
A simple node library that provides auth routes that link in with Google Cloud Platform
Downloads
2
Readme
gcp-express-auth
A simple node library that provides auth routes that link in with Google Cloud Platform.
It uses express-session
to persist users once they are logged in.
Example
First you must configure the library by importing and running configureAuth
at the top of your
express app.
Then you can add authRouter
as a middleware for your express app. This should go above all other routes.
Finally, you can use authenticateCurrentUser
to protect routes that require a user to be logged in.
const express = require('express');
const PORT = 5000;
const app = express();
const {configureAuth, authRouter, authenticateCurrentUser} = require('gcp-express-auth')
configureAuth(app)
app.use(authRouter({
clientId: '<<clientId>>',
clientSecret: '<<clientSecret>>',
googleRedirectUrl: '<<googleRedirectUrl>>'
}))
app.use('/protectedRoutes', authenticateCurrentUser, (req, res, next) => {
res.send({message: 'Protected information'})
})
app.listen(PORT, () => {
console.log(`Trafficking app listening at http://localhost:${PORT}`)
})