-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Auth0] logout then login skips redirection to login page #638
Comments
Hi there, thanks for taking the time to provide detail and a video!
So, this is correct and expected behaviour from NextAuth.js - and it's actually down to Auth0 returning a callback immediately. I appreciate it is however slightly weird flow in the case of Auth0. There are a couple of options if you don't want this behaviour:
|
|
Thanks @LoriKarikari! Do we think Auth0 is a special case where maybe we should add it by default for the provider? I don't have a strong view on it. Very happy to add that to the docs for it though - that would seem to make sense! |
@iaincollins reading the page that I linked it seems that the current flow is the default behavior for Auth0. |
@iaincollins So is there a solution to this using any of the available features in nextauth or does it still need to implemented? |
@kizzlebot You can do this in NextAuth.js, as described above. e.g. import Providers from `next-auth/providers`
...
providers: [
Providers.Auth0({
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
domain: process.env.AUTH0_DOMAIN,
authorizationUrl: `https://${process.env.AUTH0_DOMAIN}/authorize?response_type=code&prompt=consent`
})
}
... |
@iaincollins doesn't seem to solve my issue. When I log out and try to log in again, it prompts me for consent like I've never logged out. And there is no way to log out once logged in. This is whats in my import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
const options = {
// https://next-auth.js.org/configuration/providers
providers: [
Providers.Auth0({
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
domain: process.env.AUTH0_DOMAIN,
authorizationUrl: `https://${process.env.AUTH0_DOMAIN}/authorize?response_type=code&prompt=consent`
})
],
// Enable debug messages in the console if you are having problems
debug: true,
}
export default (req, res) => NextAuth(req, res, options) |
I don't think FusionAuth Logout: https://fusionauth.io/docs/v1/tech/oauth/endpoints#logout I can think of two possible reasons why it might be a good idea to add a logout flow for providers who support logout flows. Please correct me if I'm wrong!
Possible solution 1: To include an optional logoutUrl property for relevant providers in the pages/api/auth/[...nextAuth].js config. This would be configured to initiate and handle the logout flow. i.e.
Possible solution 2: Passing the req and res parameters into event callbacks. This might encourage next-auth users to add complex logic in the event callbacks which may not be ideal. Possible solution 3: To provide some way to programmatically distinguish a signIn operation from a signOut operation during the "redirect" callback. The two arguments to the redirect callback are url and baseUrl, but perhaps it could include an additional argument such as eventType which enumerates the type of event that invoked the redirect callback. This might encourage next-auth users to add complex logic in the redirect callback which may not be ideal. My current workaround: I was able to successfully implement the
NOTES TO COGNITO USERS
|
I solved this for Auth0 by setting the authorizationUrl's Providers.Auth0({
/* ... */
authorizationUrl: `https://${process.env.AUTH0_DOMAIN}/authorize?response_type=code&prompt=login`
}), Maybe this should be added as a tip to https://github.com/nextauthjs/next-auth/blob/main/www/docs/providers/auth0.md...? After reading https://github.com/nextauthjs/next-auth/blob/main/www/docs/configuration/providers.md#oauth-provider-options which describes the |
Hi @iaincollins @NickBolles, May I know how you handle the type infer for this ? Providers.Auth0({
/* ... */
authorizationUrl: `https://${process.env.AUTH0_DOMAIN}/authorize?response_type=code&prompt=login`
}), |
Hi, Create api route
Then on my logout button I used the optional callback option:
It clears my token, then logs me out of the AAD. |
Hey @iaincollins 👋, we are happily using NextAuth.js, but now we are finding ourselves to have the same issue as described in this thread. Using |
For me this works very well.
If you use Auth0 with third-party identity providers, you need to additionally add the |
Log Users Out of Identity Providers export default function handler(req, res) {
const returnTo = encodeURI('http://localhost:3000/');
res.redirect(
`https://${process.env.AUTH)_DOMAIN}/v2/logout?federated&returnTo=${returnTo}`
);
} |
Hi there, another maintainer here! I faced a similar issue with our Identity Server 4 provider at work. Our users use shared computers, and so we would like them to log out of the IdP, when they log out of any of the connected clients. The solution for this is to support federated logout (which is an OpenID Connect feature, and we don't have full coverage of these specs yet) by I raised this issue #836 a while back. Since the canary release, you can now actually create an API endpoint to federate a logout. See #836 (comment) for an example. Here is the spec: https://openid.net/specs/openid-connect-rpinitiated-1_0.html I reopen #836, and close this issue now, and if anyone would like to implement this built-in to |
|
|
const logout = async () => { This worked for me |
For anyone stumbling upon this thread, the way to force Auth0Provider({
// .. other settings
authorization: {
params: {
prompt: "login",
},
},
}), |
For anyone using appRouter with NextJS, I got this problem solved like this:
I am calling this in my Logout Button and signOut from next-auth/react. ISSUER is my auth0 domain. Hope this helps someone. |
Describe the bug
When a user first logs in using auth0, they are redirected correctly to auth0's login page and redirected back and authenticated as expected. If the user logs out, then clicks on login again,
next-auth
doesn't redirect the user to login page again; it automatically logs the user in.This can be reproduced on the example application
Steps to reproduce
auth0
Sign In
again (The user is not sent to the login page)Expected behavior
The user is redirected to the login page whenever they click on sign in.
The text was updated successfully, but these errors were encountered: