fix: Corriger l'erreur Invalid URL quand VITE_OAUTH_PORTAL_URL est absent
- Ajouter un guard dans getLoginUrl() pour rediriger vers /login
quand VITE_OAUTH_PORTAL_URL n'est pas configuré
- Évite le crash new URL('undefined/app-auth') sur la page d'accueil
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
export { COOKIE_NAME, ONE_YEAR_MS } from "@shared/const";
|
||||
|
||||
// Generate login URL at runtime so redirect URI reflects the current origin.
|
||||
export const getLoginUrl = () => {
|
||||
const oauthPortalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL;
|
||||
const appId = import.meta.env.VITE_APP_ID;
|
||||
// If OAuth is not configured, redirect to local login page
|
||||
if (!oauthPortalUrl) {
|
||||
return "/login";
|
||||
}
|
||||
const redirectUri = `${window.location.origin}/api/oauth/callback`;
|
||||
const state = btoa(redirectUri);
|
||||
|
||||
const url = new URL(`${oauthPortalUrl}/app-auth`);
|
||||
url.searchParams.set("appId", appId);
|
||||
url.searchParams.set("redirectUri", redirectUri);
|
||||
url.searchParams.set("state", state);
|
||||
url.searchParams.set("type", "signIn");
|
||||
|
||||
return url.toString();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user