mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-21 20:07:33 +00:00
feat: add login expiry check
This commit is contained in:
parent
afbdc56b71
commit
2c56336c4f
@ -1,9 +1,10 @@
|
||||
<script>
|
||||
import { token } from "./stores.js";
|
||||
import { isTokenExpired } from "./login-check.js";
|
||||
|
||||
let loggedIn = false;
|
||||
token.subscribe((value) => {
|
||||
loggedIn = value !== "";
|
||||
loggedIn = !isTokenExpired(value);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -2,10 +2,11 @@
|
||||
import { token } from "./stores.js";
|
||||
import { navigate } from "svelte-routing";
|
||||
import { onMount } from "svelte";
|
||||
import { isTokenExpired } from "./login-check.js";
|
||||
|
||||
let loggedIn = false;
|
||||
token.subscribe((value) => {
|
||||
loggedIn = value !== "";
|
||||
loggedIn = !isTokenExpired(value);
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
|
@ -1,12 +1,13 @@
|
||||
<script>
|
||||
import { Link } from "svelte-routing";
|
||||
import { token } from "./stores.js";
|
||||
import { isTokenExpired } from "./login-check.js";
|
||||
|
||||
let menu_shown = false;
|
||||
|
||||
let loggedIn = false;
|
||||
token.subscribe((value) => {
|
||||
loggedIn = value !== "";
|
||||
loggedIn = !isTokenExpired(value);
|
||||
});
|
||||
|
||||
const toggleMenu = () => {
|
||||
|
8
web/app/src/login-check.js
Normal file
8
web/app/src/login-check.js
Normal file
@ -0,0 +1,8 @@
|
||||
const isTokenExpired = (token) => {
|
||||
if (token === "") return true;
|
||||
|
||||
const expiry = (JSON.parse(atob(token.split('.')[1]))).exp;
|
||||
return (Math.floor((new Date).getTime() / 1000)) >= expiry;
|
||||
}
|
||||
|
||||
export { isTokenExpired }
|
Loading…
Reference in New Issue
Block a user