From 7a95444cf9177d6d5b869eaf5134bf1d3ee36b90 Mon Sep 17 00:00:00 2001 From: BloxerHD018 Date: Thu, 2 Jul 2026 20:33:34 +0100 Subject: [PATCH] Handle OAuthErrorRespose from Account --- src/api/v1/login.rs | 7 ++++--- static/js/login.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/api/v1/login.rs b/src/api/v1/login.rs index 5680e79..0a7b2a7 100644 --- a/src/api/v1/login.rs +++ b/src/api/v1/login.rs @@ -22,9 +22,10 @@ struct TokenRequest { #[derive(Serialize, Deserialize)] struct TokenResponse { - access_token: String, - token_type: String, - expires_in: i64, + access_token: Option, + token_type: Option, + expires_in: Option, + error: Option, } pub fn router() -> Router { diff --git a/static/js/login.js b/static/js/login.js index c0a2979..7d93824 100644 --- a/static/js/login.js +++ b/static/js/login.js @@ -41,6 +41,21 @@ async function generateToken(username, password) { const data = await response.json(); + if (data["error"]) { + let error = data["error"]; + if (error == "invalid_client" || error == "unsupported_grant_type") { + loginError("Website is misconfigured, contact a SPFN developer to fix this", 502); + } else if (error == "invalid_request") { + loginError("Website sent invalid data to account, contact a SPFN developer to fix this", 502); + } else if (error == "invalid_grant") { + loginError("Invalid SFID or Password"); + } else { + loginError(error); + } + + throw new Error(`Token Generation Returned Error: ${data["error"]}`); + } + sessionStorage.setItem("authToken", data["access_token"]); const expiry = Date.now() + (data["expires_in"] * 1000);