Fix permanent login failure after Zitadel restarts
getOidcConfig() memoized the discovery promise even when it rejected, so a single failed OIDC discovery (e.g. Zitadel not ready yet when the dev server starts) permanently broke /auth/login until the process was restarted. Clear the cached promise on rejection so it retries.
This commit is contained in:
@@ -17,7 +17,7 @@ export interface Session extends SessionUser {
|
|||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
let configPromise: Promise<client.Configuration>;
|
let configPromise: Promise<client.Configuration> | undefined;
|
||||||
export function getOidcConfig(): Promise<client.Configuration> {
|
export function getOidcConfig(): Promise<client.Configuration> {
|
||||||
configPromise ??= (async () => {
|
configPromise ??= (async () => {
|
||||||
const issuer = new URL(authConfig.issuer);
|
const issuer = new URL(authConfig.issuer);
|
||||||
@@ -28,7 +28,10 @@ export function getOidcConfig(): Promise<client.Configuration> {
|
|||||||
return secret
|
return secret
|
||||||
? client.discovery(issuer, authConfig.clientId, secret, undefined, options)
|
? client.discovery(issuer, authConfig.clientId, secret, undefined, options)
|
||||||
: client.discovery(issuer, authConfig.clientId, undefined, client.None(), options);
|
: client.discovery(issuer, authConfig.clientId, undefined, client.None(), options);
|
||||||
})();
|
})().catch((exception) => {
|
||||||
|
configPromise = undefined;
|
||||||
|
throw exception;
|
||||||
|
});
|
||||||
return configPromise;
|
return configPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user