Hey,
I’ve seen a range of folk raising logout-doesn’t-really-logout, I’d like to try again. Failing this I will raise a ticket on the nextjs-auth0 Github project.
I don’t consider my implementation anything other than standard, that is to say:
- Login button with href /api/auth/login?returnTo=/dashboard
- Out of the box middleware.ts for protecting /dashboard/*
- A logout button with href /api/auth/logout
If I click my Login button, I’ll go to the Auth0 universal login, and get redirected to my /dashboard page, with all the user hooks working. Excellent. I can see a cookie called appSession
.
If I click logout, I get taken back to my / login page. I can see the appSession
cookie is removed.
BUT
If I tap login, to go to /api/auth/login?returnTo=/dashboard then I am automatically logged into /dashboard, without the Auth0 universal login.
This is challenging, because I am trying to test with many users in development, so I need to be able to properly logout. It’s also IMO a security risk if this happens in production, as if I want to logout my session, someone in a coffee shop should not be able to tap login and expect to be logged in.
One thing that DOES work is overwriting the /api/auth/[auth0]/route.ts as follows:
import { handleAuth, handleLogout } from "@auth0/nextjs-auth0";
import { NextResponse } from "next/server";
// export const GET = handleAuth();
export const GET = handleAuth({
logout: async (req, res) => {
return NextResponse.redirect(
process.env.AUTH0_LOGOUT_OIDC +
"?post_logout_redirect_uri=" +
encodeURIComponent(process.env.AUTH0_BASE_URL)
);
},
});
This follows the info at Use the OIDC Endpoint to Log Users Out of Auth0, except:
- The final logged out screen has no way for the user to get back to the original site loging page
- The post_logout_redirect_uri is ignored, despite being described as operational at Use the OIDC Endpoint to Log Users Out of Auth0 and despite my adding it to both Tenant Settings, and my Application Settings - in the allowable Logout URL fields
My questions are:
- How are others logging out users using the auth0-nextjs library?
- Are others finding that login is not always requires despite calling logout?
- Are others using this OIDC approach to logging out at the identity provider side and if so, does post_logout_redirect work?