Search code examples
next-auth

Complete Logout using NextAuth


Using NextAuth 4 or 5 I need to create the following:

  1. Log in into my app using Azure Active Directory
  2. Allow authenticated users to use my app.-
  3. Log out of my app.

All works fine, but:

When the user logs out using signOut(), all it needs to log in again is to call signIn(). At the second login the user is not asked for his credentials, so somebody seeing his PC can login without being asked for username / password.

Is there a way to force NextAuth / Azure AD into asking for credentials at EVERY call to signIn()


Solution

  • Have you tried to use the prompt parameter? An example in JS could look like this

    import NextAuth from "next-auth";
    import AzureADProvider from "next-auth/providers/azure-ad";
    
    export default NextAuth({
      providers: [
        AzureADProvider({
          clientId: "...",
          clientSecret: "...",
          tenantId: "...",
          authorization: {
            params: {
              prompt: "login", // Force re-authentication
            },
          },
        }),
      ],
    });