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_ID=OurFrontEndClient
KEYCLOAK_SECRET=**************************
KEYCLOAK_ISSUER=ourkeycloackclient

NEXTAUTH_URL=
NEXTAUTH_SECRET=*****************************

Keycloak setting
Base URLBase URL :https://ourdomain.in/
Valid Redirect URIs : . (works fine)
When Valid Redirect URIs is set to ourdomain.in/
, “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 ?
[next-auth][error][CALLBACK_OAUTH_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??

NEXTAUTH_URL=https://ourdomain.in/pages/api/auth/

In Keyclock client config

  • Valid Redirect URIs =https://ourdomain.in/pages/api/auth/*
    Root URL =https://ourdomain.in
    Base URL=https://ourdomain.in
    Admin URL=https://ourdomain.in