-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add session validation and logout mechanism
- Loading branch information
Björn Urban
committed
Jul 28, 2024
1 parent
8c1a437
commit d39b33a
Showing
5 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const isAuthenticated = writable(false); | ||
function createAuthStore() { | ||
const { subscribe, set } = writable(false); | ||
|
||
return { | ||
subscribe, | ||
setAuth: (value) => { | ||
set(value); | ||
if (typeof window !== 'undefined') { | ||
localStorage.setItem('isAuthenticated', JSON.stringify(value)); | ||
} | ||
}, | ||
checkAuth: () => { | ||
if (typeof window !== 'undefined') { | ||
const storedAuth = localStorage.getItem('isAuthenticated'); | ||
if (storedAuth) { | ||
set(JSON.parse(storedAuth)); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export const isAuthenticated = createAuthStore(); |