From 0b3afc6492126c8dba50b7f41fcb7312519abe3d Mon Sep 17 00:00:00 2001 From: BloxerHD018 Date: Sun, 21 Jun 2026 22:56:43 +0100 Subject: [PATCH] Fix Login Page for New Token Method --- js/accounts.js | 5 +++-- js/login.js | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/js/accounts.js b/js/accounts.js index 96bdced..0060fab 100644 --- a/js/accounts.js +++ b/js/accounts.js @@ -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" diff --git a/js/login.js b/js/login.js index 94976a8..4456f3c 100644 --- a/js/login.js +++ b/js/login.js @@ -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) {