commit 30658db52ce3d19151eff920b5b311a8103fe2e6
parent 8cddff6b50467ca09931593a99844efe16659e89
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sat, 31 Aug 2024 19:40:01 -0700
Update api authorization test
Rename from logged_in to authorized and use it in all cases it can
be instead of authorized_duration().
Diffstat:
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/files/lib/api.js b/files/lib/api.js
@@ -119,7 +119,7 @@ export function authorized_duration(t) {
return Number(exp) - Math.trunc(Date.now() / 1000)
}
-export function logged_in() {
+export function authorized() {
return authorized_duration() > 0
}
diff --git a/files/lib/etc.js b/files/lib/etc.js
@@ -36,7 +36,7 @@ export function bar(on) {
let right = nav.appendChild(document.createElement("ul"))
right.classList.add("right")
- if (!api.logged_in()) {
+ if (!api.authorized()) {
additem(right, link("Login", "/login", "log-in"))
} else {
additem(left, link("Floorplans", "/floorplans"))
@@ -49,7 +49,7 @@ export function bar(on) {
}
export function authorize() {
- if (api.authorized_duration() <= 0) {
+ if (!api.authorized()) {
// Maybe add a parameter which has /login redirect
// back to the page that was trying to be accessed
window.location.href = "/login"
diff --git a/files/login/main.js b/files/login/main.js
@@ -5,7 +5,7 @@ import * as ui from "/lib/ui.js"
let default_page = "/floorplans"
function init() {
- if (api.authorized_duration() > 0) {
+ if (api.authorized()) {
window.location.href = default_page
}
diff --git a/files/register/main.js b/files/register/main.js
@@ -2,7 +2,7 @@ import * as api from "/lib/api.js"
import * as etc from "/lib/etc.js"
function init() {
- if (api.authorized_duration() > 0) {
+ if (api.authorized()) {
// Maybe don't do this?
window.location.href = "/floorplans"
}
diff --git a/files/services/main.js b/files/services/main.js
@@ -14,7 +14,7 @@ function main() {
function chooseService(service) {
console.log("Choose service", service.id)
- if (!api.logged_in()) {
+ if (!api.authorized()) {
window.location.href = "/register"
}
diff --git a/files/settings/billing/main.js b/files/settings/billing/main.js
@@ -2,7 +2,7 @@ import * as etc from "/lib/etc.js"
import * as api from "/lib/api.js"
function main() {
- if (!api.logged_in()) {
+ if (!api.authorized()) {
window.location.href = "/login"
}