From 3f51d89c37fe7f9772762b56a063bd4b67dcb76a Mon Sep 17 00:00:00 2001 From: dewanakl Date: Mon, 9 Dec 2024 09:17:28 +0700 Subject: [PATCH] feat: clear session if exp --- js/admin.js | 4 +++- js/util.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/admin.js b/js/admin.js index aeaa067..d03927f 100644 --- a/js/admin.js +++ b/js/admin.js @@ -252,11 +252,13 @@ export const admin = (() => { try { // window.atob can throw error - if (!session.isAdmin() || !session.getToken() || (JSON.parse(window.atob((session.getToken()).split('.')[1]))?.exp ?? 0) < (Date.now() / 1000)) { + if (!session.isAdmin() || !session.getToken() || (JSON.parse(window.atob(session.getToken().split('.')[1]))?.exp ?? 0) < (Date.now() / 1000)) { throw new Error('invalid token'); } } catch { bootstrap.Modal.getOrCreateInstance('#loginModal').show(); + session.logout(); + user.clear(); return; } diff --git a/js/util.js b/js/util.js index f5d7cd3..d3c2750 100644 --- a/js/util.js +++ b/js/util.js @@ -109,7 +109,7 @@ export const util = (() => { const base64Decode = (str) => { const decoder = new TextDecoder(); - const decodedBytes = Uint8Array.from(atob(str), (c) => c.charCodeAt(0)); + const decodedBytes = Uint8Array.from(window.atob(str), (c) => c.charCodeAt(0)); return decoder.decode(decodedBytes); };