Queue password checks and shorten busy retries (Refs #95)
CI / checks (push) Successful in 4m36s
CI / checks (push) Successful in 4m36s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { error, isHttpError, json, type Cookies } from '@sveltejs/kit';
|
||||
import { AuthError, SESSION_COOKIE, type AuthResult } from './index.js';
|
||||
import { PasswordServiceBusyError } from './passwords.js';
|
||||
import type { AuthUser } from '../../auth.js';
|
||||
|
||||
export function sessionCookie(url: URL): string {
|
||||
@@ -85,7 +86,7 @@ export function authError(cause: unknown): Response {
|
||||
const status =
|
||||
cause instanceof AuthError
|
||||
? cause.status
|
||||
: message.includes('busy')
|
||||
: cause instanceof PasswordServiceBusyError
|
||||
? 429
|
||||
: message.startsWith('Use a password')
|
||||
? 400
|
||||
@@ -96,7 +97,14 @@ export function authError(cause: unknown): Response {
|
||||
status,
|
||||
headers: {
|
||||
'Cache-Control': 'no-store',
|
||||
...(status === 429 ? { 'Retry-After': '900' } : {})
|
||||
...(status === 429
|
||||
? {
|
||||
'Retry-After':
|
||||
cause instanceof PasswordServiceBusyError
|
||||
? String(cause.retryAfterSeconds)
|
||||
: '900'
|
||||
}
|
||||
: {})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user