-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract
injectExpressRoutes
- Loading branch information
1 parent
dc51b1d
commit 23d6e6b
Showing
3 changed files
with
40 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// @ts-check | ||
|
||
/** @returns {import('../my-http-wrapper/http/AuthFeatures').AuthFeatures} */ | ||
exports.makeAuthFeatures = () => { | ||
const { Auth0Wrapper } = require('.'); | ||
|
||
return { | ||
/** | ||
* Attach /login, /logout, and /signup routes to Express.js application server. | ||
* @param {import('express').Express} app | ||
* @param {string} urlPrefix | ||
*/ | ||
injectExpressRoutes(app, urlPrefix) { | ||
const auth0 = new Auth0Wrapper(process.env); // throws if required env vars are missing | ||
|
||
// attach /login, /logout, and /callback routes to the baseURL | ||
app.use(auth0.makeExpressAuthMiddleware(urlPrefix)); | ||
|
||
// redirects to Auth0's sign up dialog | ||
app.get( | ||
'/signup', | ||
auth0.makeSignupRoute({ | ||
returnTo: '/register', // so we can create the user in our database too | ||
}), | ||
Check failure Code scanning / CodeQL Missing rate limiting High
This route handler performs
authorization Error loading related location Loading |
||
); | ||
}, | ||
}; | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Express } from 'express'; | ||
|
||
export interface AuthFeatures { | ||
injectExpressRoutes(app: Express, urlPrefix: string); | ||
} |