gcp-express-auth

1.0.0 • Public • Published

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}`)
})

Readme

Keywords

none

Package Sidebar

Install

npm i gcp-express-auth

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.46 kB

Total Files

9

Last publish

Collaborators

  • campbellbrobbel