- Published
- Author
- Adithya HebbarSystem Analyst
To logout from
#keycloak #nextauth #nextjs #js
Keycloak using the signOut function in NextAuth, you need to override the default behavior to ensure that the user is properly logged out from Keycloak as well. Here's how you can update your signOut function:Code
async signOut({ token }) {
if (token.provider === "keycloak") {
const issuerUrl = authOptions.providers.find((p) => p.id === "keycloak")
.options!.issuer!;
const logOutUrl = new URL(
`${issuerUrl}/protocol/openid-connect/logout`
);
logOutUrl.searchParams.set("id_token_hint", token.id_token!);
await fetch(logOutUrl);
}
}#keycloak #nextauth #nextjs #js