Fix Login Page for New Token Method
All checks were successful
Build and Push Image / spfn-website (push) Successful in 31s

This commit is contained in:
BloxerHD 2026-06-21 22:56:43 +01:00
commit 0b3afc6492
Signed by: bloxerhd018
SSH key fingerprint: SHA256:ItSfcfhpXlfkMK3uQSDYW5X3XKm0hbHWQqWcCK57px8
2 changed files with 12 additions and 8 deletions

View file

@ -44,7 +44,7 @@ function logOut() {
window.onload = async function() {
let expiryStr = sessionStorage.getItem("authExpires");
if (expiryStr) {
let expiry = new Date(expiryStr);
let expiry = new Date(parseInt(expiryStr));
if (expiry > new Date()) { // Hasn't expired - Get user data
let token = sessionStorage.getItem("authToken");
@ -63,7 +63,8 @@ window.onload = async function() {
document.getElementById("loading-screen").style.display = "none";
} else { // Has expired - Prompt user to log back in
window.location.href = "/account/login?redirect=/account"
console.log("Token Expired")
//window.location.href = "/account/login?redirect=/account"
}
} else { // User has never logged in for this session
window.location.href = "/account/login?redirect=/account"

View file

@ -14,13 +14,16 @@ function loginError(message, code = null) {
async function generateToken(username, password) {
const credentials = btoa(`${username} ${password}`);
const body = `grant_type=password&username=${username}&password=${password}&client_id=website`
let response;
try {
response = await fetch("https://account.spfn.net/api/v2/oauth2/generate_token", {
method: "GET",
method: "POST",
headers: {
"Authorization": `Basic ${credentials}`,
}
"Content-Type": "application/x-www-form-urlencoded"
},
body,
})
} catch (err) {
loginError(`Internal Server Error: ${err.message}`)
@ -39,11 +42,11 @@ async function generateToken(username, password) {
const data = await response.json();
sessionStorage.setItem("authToken", data["token"])
sessionStorage.setItem("authToken", data["access_token"]);
const expiry = data["expiry"].slice(0, 19) + "Z"
const expiry = Date.now() + (data["expires_in"] * 1000);
sessionStorage.setItem("authExpires", expiry)
return data["token"];
return data["access_token"];
}
async function getToken(username, password) {