Fix Login Page for New Token Method
All checks were successful
Build and Push Image / spfn-website (push) Successful in 31s
All checks were successful
Build and Push Image / spfn-website (push) Successful in 31s
This commit is contained in:
parent
d1d9c14b8a
commit
0b3afc6492
2 changed files with 12 additions and 8 deletions
|
|
@ -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"
|
||||
|
|
|
|||
15
js/login.js
15
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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue