Last active
February 8, 2022 01:36
-
-
Save antony/9ba78a9c68ce31ed8ffb97fd64b9acf7 to your computer and use it in GitHub Desktop.
Auth0 SSR Compatible Integration with Sapper
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
npm install --save express express-openid-connect |
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
// See reddit post here https://www.reddit.com/r/sveltejs/comments/fqar1y/integrating_auth0_with_sapper_in_10_lines/ | |
import sirv from 'sirv' | |
import express from 'express' | |
import compression from 'compression' | |
import * as sapper from '@sapper/server' | |
import { auth } from 'express-openid-connect' | |
const { PORT, NODE_ENV } = process.env | |
const dev = NODE_ENV === 'development' | |
express() | |
.use( | |
compression({ threshold: 0 }), | |
sirv('static', { dev }), | |
auth({ | |
required: false, | |
auth0Logout: true, | |
baseURL: 'http://localhost:3000', | |
issuerBaseURL: 'https://your-hosted-url.auth0.com', | |
clientID: 'your-client-id', | |
appSessionSecret: 'your-session-secret' | |
}), | |
(req, res, next) => { | |
return sapper.middleware({ | |
session: () => { | |
return { | |
isAuthenticated: req.isAuthenticated(), | |
user: req.openid.user | |
} | |
} | |
})(req, res, next) | |
} | |
) | |
.listen(PORT, err => { | |
if (err) console.log('error', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
~~appSessionSecret: OAUTH_CLIENT_SECRET ~~
with
;-)