Created
April 19, 2022 01:58
-
-
Save ganeshan/8cd23fa5b8d5be291a049703e2e0533e to your computer and use it in GitHub Desktop.
Barebones NodeJS app - Add Node.js User Authentication in 10 Minutes!
This file contains hidden or 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
| const { auth, requiresAuth } = require('express-openid-connect'); | |
| const express = require('express'); | |
| require('dotenv').config(); | |
| const app = express(); | |
| const port = process.env.PORT || 3000; | |
| const config = { | |
| authRequired: false, | |
| auth0Logout: true, | |
| baseURL: process.env.BASE_URL, | |
| clientID: process.env.CLIENT_ID, | |
| issuerBaseURL: process.env.ISSUER_BASE_URL, | |
| secret: process.env.SECRET | |
| }; | |
| // auth router attaches /login, /logout, and /callback routes to the baseURL | |
| app.use(auth(config)); | |
| // req.isAuthenticated is provided from the auth router | |
| app.get('/', (req, res) => { | |
| res.send(req.oidc.isAuthenticated() ? 'Logged in' : 'Logged out') | |
| }); | |
| app.get('/profile', requiresAuth(), (req, res) => { | |
| res.json(req.oidc.user); | |
| }); | |
| app.listen(port, () => { | |
| console.log(`Listening on port: ${port}`) | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The video link:
https://www.youtube.com/watch?v=QQwo4E_B0y8