fix: address logic error in user authentication flow
CI / build-and-test (push) Failing after -31m47s

* Corrected condition for user role validation
* Improved error handling for failed login attempts
This commit is contained in:
2026-04-26 10:37:38 +02:00
parent 71845d38d3
commit da7220ad64
6 changed files with 96 additions and 34 deletions
+20
View File
@@ -238,6 +238,26 @@ export async function buildOAuthAuthorizationURL(): Promise<string> {
return url.toString();
}
export async function loginWithCredentials(username: string, password: string): Promise<string> {
const base = getPublicBaseURL();
const response = await fetch(`${base}/api/oauth/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: username,
client_secret: password
})
});
const payload = (await response.json()) as { access_token?: string; error?: string };
if (!response.ok || !payload.access_token) {
throw new Error(payload.error || `Login failed (${response.status})`);
}
return payload.access_token;
}
export async function exchangeOAuthCode(code: string, returnedState: string): Promise<string> {
const session = readOAuthSession();
if (!session) {