fix: seed OIDC clients after DB init completes
Move OIDC client seeding into the database init IIFE to prevent race condition where seeding runs before tables are created. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f19a5b9904
commit
4665d14633
|
|
@ -5289,7 +5289,7 @@ app.get('/', (c) => {
|
||||||
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
||||||
try {
|
try {
|
||||||
await initDatabase();
|
await initDatabase();
|
||||||
return;
|
break;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`EncryptID: Database init attempt ${attempt}/${maxRetries} failed:`, (err as Error).message);
|
console.error(`EncryptID: Database init attempt ${attempt}/${maxRetries} failed:`, (err as Error).message);
|
||||||
if (attempt === maxRetries) {
|
if (attempt === maxRetries) {
|
||||||
|
|
@ -5299,19 +5299,8 @@ app.get('/', (c) => {
|
||||||
await new Promise(r => setTimeout(r, attempt * 2000));
|
await new Promise(r => setTimeout(r, attempt * 2000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
// Clean expired challenges, recovery tokens, fund claims, and OIDC codes every 10 minutes
|
// Seed OIDC clients from environment (after DB is ready)
|
||||||
setInterval(() => {
|
|
||||||
cleanExpiredChallenges().catch(() => {});
|
|
||||||
cleanExpiredRecoveryTokens().catch(() => {});
|
|
||||||
cleanExpiredFundClaims().catch(() => {});
|
|
||||||
cleanExpiredOidcCodes().catch(() => {});
|
|
||||||
cleanExpiredIdentityInvites().catch(() => {});
|
|
||||||
}, 10 * 60 * 1000);
|
|
||||||
|
|
||||||
// Seed OIDC clients from environment (OIDC_CLIENTS=json array or individual env vars)
|
|
||||||
(async () => {
|
|
||||||
try {
|
try {
|
||||||
const clientsJson = process.env.OIDC_CLIENTS;
|
const clientsJson = process.env.OIDC_CLIENTS;
|
||||||
if (clientsJson) {
|
if (clientsJson) {
|
||||||
|
|
@ -5324,6 +5313,15 @@ setInterval(() => {
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Clean expired challenges, recovery tokens, fund claims, and OIDC codes every 10 minutes
|
||||||
|
setInterval(() => {
|
||||||
|
cleanExpiredChallenges().catch(() => {});
|
||||||
|
cleanExpiredRecoveryTokens().catch(() => {});
|
||||||
|
cleanExpiredFundClaims().catch(() => {});
|
||||||
|
cleanExpiredOidcCodes().catch(() => {});
|
||||||
|
cleanExpiredIdentityInvites().catch(() => {});
|
||||||
|
}, 10 * 60 * 1000);
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
╔═══════════════════════════════════════════════════════════╗
|
╔═══════════════════════════════════════════════════════════╗
|
||||||
║ ║
|
║ ║
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue