Skip to content

Commit d5d8efd

Browse files
committed
feat: read post-login redirect URL from environment variable
1 parent 472a137 commit d5d8efd

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ ZITADEL_CALLBACK_URL="http://localhost:3000/api/auth/callback/zitadel"
8080
# Redirect URI configured in your ZITADEL application settings.
8181
ZITADEL_POST_LOGOUT_URL="http://localhost:3000/api/auth/logout/callback"
8282
83+
# Optional. URL where users are redirected after successful login.
84+
# Defaults to "/profile" if not specified.
85+
ZITADEL_POST_LOGIN_URL="/profile"
86+
8387
# Auth.js base URL for your application. In development, this is typically
8488
# http://localhost:3000. In production, use your actual domain.
8589
AUTH_TRUST_HOST=true

src/lib/auth.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ export function createAuthOptions(getEnv: GetEnvFunction): FullAuthConfig {
281281
* @returns The URL to redirect the user to after successful login
282282
*/
283283
async redirect({ baseUrl }: { baseUrl: string }) {
284-
return `${baseUrl}/profile`;
284+
const postLoginUrl = getEnv('ZITADEL_POST_LOGIN_URL') || '/profile';
285+
return postLoginUrl.startsWith('http')
286+
? postLoginUrl
287+
: `${baseUrl}${postLoginUrl}`;
285288
},
286289

287290
/**

0 commit comments

Comments
 (0)