Keycloak login redirects to localhost

Hello ,
we are using keycloak for our nextjs webapp authentication.
If I run in localhost, its redirects perfectly, but when we deploy it to the server
1.It redirects to keycloak login page perfectly
2. After login ,it redirects to http://localhost:3000/api/auth/callback/keycloak… instead of webapp home page

.env file


Keycloak setting
Base URLBase URL :
Valid Redirect URIs : . (works fine)
When Valid Redirect URIs is set to
, “Invalid parameter: redirect_uri” error occurs and no login page appears
Why and where is it redirecting to localhost??
Any idea how to avoid redirects to localhost and redirect_uri error ?

You need to configure your app to pass the correct redirect uri to keycloak (i guess nextauth_URL is it:
Options | NextAuth.js) and then add this uri (as exact as possible in the keycloak client config.

thanks for reply @bpedersen2.
is following correct configuration??


In Keyclock client config

  • Valid Redirect URIs =*
    Root URL =
    Base URL=
    Admin URL=