Skip to content

Commit

Permalink
feat: clear session if exp
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Dec 9, 2024
1 parent 382b8d7 commit 3f51d89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 3f51d89

Please sign in to comment.