fix: address logic error in user authentication flow
CI / build-and-test (push) Failing after -31m47s
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user