Skip to content
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

[SDK-3567] Allow response customization in afterCallback #838

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

adamjmcgrath
Copy link
Contributor

📋 Changes

Allow customisation of the response in afterCallback to enabled a couple of use cases

  1. Terminating the request if a condition in the claim is not met.
const afterCallback = (req, res, session, state) => {
  if (session.user.isAdmin) {
    return session;
  } else {
    res.status(401).end('User is not admin');
  }
}; // Terminates the request with 401 if user is not admin
  1. Customising the return to url based on the claims
const afterCallback = (req, res, session, state) => {
  if (!session.user.isAdmin) {
    res.setHeader('Location', '/admin');
  }
  return session;
}; // Redirects to `/admin` if user is admin

@adamjmcgrath adamjmcgrath added the review:medium Medium review label Oct 4, 2022
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner October 4, 2022 10:21
@vercel
Copy link

vercel bot commented Oct 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nextjs-auth0 ⬜️ Ignored (Inspect) Oct 4, 2022 at 10:21AM (UTC)

@adamjmcgrath adamjmcgrath changed the title Allow response customization in afterCallback [SDK-3567] Allow response customization in afterCallback Oct 4, 2022
@adamjmcgrath adamjmcgrath merged commit eeef5d0 into vNext Oct 4, 2022
@adamjmcgrath adamjmcgrath deleted the end-in-after-callback branch October 4, 2022 11:56
@adamjmcgrath adamjmcgrath mentioned this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants