Handle OAuthErrorRespose from Account
This commit is contained in:
parent
517a9fad39
commit
a5cc09537b
2 changed files with 19 additions and 3 deletions
|
|
@ -22,9 +22,10 @@ struct TokenRequest {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct TokenResponse {
|
struct TokenResponse {
|
||||||
access_token: String,
|
access_token: Option<String>,
|
||||||
token_type: String,
|
token_type: Option<String>,
|
||||||
expires_in: i64,
|
expires_in: Option<i64>,
|
||||||
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,21 @@ async function generateToken(username, password) {
|
||||||
|
|
||||||
const data = await response.json();
|
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"]);
|
sessionStorage.setItem("authToken", data["access_token"]);
|
||||||
|
|
||||||
const expiry = Date.now() + (data["expires_in"] * 1000);
|
const expiry = Date.now() + (data["expires_in"] * 1000);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue