mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-22 12:27:33 +00:00
feat: add login expiry check
This commit is contained in:
parent
afbdc56b71
commit
2c56336c4f
@ -1,9 +1,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import { token } from "./stores.js";
|
import { token } from "./stores.js";
|
||||||
|
import { isTokenExpired } from "./login-check.js";
|
||||||
|
|
||||||
let loggedIn = false;
|
let loggedIn = false;
|
||||||
token.subscribe((value) => {
|
token.subscribe((value) => {
|
||||||
loggedIn = value !== "";
|
loggedIn = !isTokenExpired(value);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
import { token } from "./stores.js";
|
import { token } from "./stores.js";
|
||||||
import { navigate } from "svelte-routing";
|
import { navigate } from "svelte-routing";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
import { isTokenExpired } from "./login-check.js";
|
||||||
|
|
||||||
let loggedIn = false;
|
let loggedIn = false;
|
||||||
token.subscribe((value) => {
|
token.subscribe((value) => {
|
||||||
loggedIn = value !== "";
|
loggedIn = !isTokenExpired(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
<script>
|
<script>
|
||||||
import { Link } from "svelte-routing";
|
import { Link } from "svelte-routing";
|
||||||
import { token } from "./stores.js";
|
import { token } from "./stores.js";
|
||||||
|
import { isTokenExpired } from "./login-check.js";
|
||||||
|
|
||||||
let menu_shown = false;
|
let menu_shown = false;
|
||||||
|
|
||||||
let loggedIn = false;
|
let loggedIn = false;
|
||||||
token.subscribe((value) => {
|
token.subscribe((value) => {
|
||||||
loggedIn = value !== "";
|
loggedIn = !isTokenExpired(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleMenu = () => {
|
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