-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat[auth]: handle new blocked users and trial expiry in token flow #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { getAccessToken, withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
| import { getAccessToken, getSession, withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
| import { NextApiRequest, NextApiResponse } from "next"; | ||
|
|
||
| export default process.env.NEXT_PUBLIC_DEV_MODE === "true" | ||
|
|
@@ -19,8 +19,16 @@ export default process.env.NEXT_PUBLIC_DEV_MODE === "true" | |
| } | ||
| try { | ||
| const accessToken = await getAccessToken(req, res); | ||
| const session = await getSession(req, res); | ||
| const trialEndsAt = session?.user?.trial_ends_at; | ||
| if (trialEndsAt && new Date(trialEndsAt) < new Date()) { | ||
| return res.status(403).json({ error: "trial_expired", email: session?.user?.email }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to write any unit tests for this? Maybe mocking Auth0 is too hard?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For unit tests yeah definitely too much, but we could try to add a Cypress test for this actually 👍 I'll add to that issue |
||
| res.status(200).json(accessToken); | ||
| } catch (error: any) { | ||
| if (error.message?.includes("access_denied")) { | ||
| return res.status(403).json({ error: "access_denied", message: error.message }); | ||
| } | ||
| res.status(error.status || 400).end(error.message); | ||
| } | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is children being used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just allows us to inject child components into the Header when needed, e.g. for this PR having a Sign Out on the Blocked/Access Denied screen (in case a user logs in with the wrong email address to let them still sign out from that page)