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

v4: Customize auth handlers #1895

Open
5 tasks done
mvvmm opened this issue Feb 10, 2025 · 4 comments
Open
5 tasks done

v4: Customize auth handlers #1895

mvvmm opened this issue Feb 10, 2025 · 4 comments
Labels

Comments

@mvvmm
Copy link

mvvmm commented Feb 10, 2025

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

In v3, we could customize the auth handlers in /api/auth/[auth0] via something like:

export const GET = handleAuth({
  async logout(req: NextApiRequest, res: NextApiResponse) {

   // do custom stuff

   return await handleLogout(req, res);
  },
});

Reference:

I'm not finding that something similar exists in v4.

Describe the ideal solution

Ability to customize the auth handlers in v4.

The handleLogout() helper is an important piece of this. We need the ability to write our own custom code and then rely on the default auth handler as a fallback, or in addition to our custom code.

Alternatives and current workarounds

Depends on the use case, but as far as I can tell, there is no way to run custom code in the middle of those new auth handlers, /auth/logout, for example.

Additional context

No response

@priley86
Copy link

priley86 commented Mar 3, 2025

+1'ing this request here. As an aside, if you are simply looking to update session post /auth/callback, you may want to look at the beforeSessionSaved and onCallback hooks. These ended up fitting my usecase ok here for the moment.
https://github.com/auth0/nextjs-auth0/blob/47e45ee9ea46b4670fed2566a9caa17b2d6fbc02/EXAMPLES.md#hooks

@maninderpreetsingh
Copy link

It's also not taking the basePath from next.config.

@priley86
Copy link

priley86 commented Mar 7, 2025

@maninderpreetsingh - yes that appears to be the root of this issue, the logic here that is:
https://github.com/auth0/nextjs-auth0/blob/main/src/server/auth-client.ts#L225-L250

As a heads up to maintainers, this issue (which was recently fixed) is closely related and should be tested alongside w/ any changes for this callback customization. It seems after those changes are applied currently though, the APP_BASE_URL is respected as far as request path goes.

@srowe0091
Copy link

srowe0091 commented Mar 17, 2025

Has there been updates or resolution to this? I'm also not seeing anywhere how to replace the current handles in version 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants