-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Github lost our code :)
- Loading branch information
Showing
23 changed files
with
262 additions
and
156 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { defineStore } from 'pinia'; | ||
import { ref } from 'vue'; | ||
import router from '@/router'; | ||
|
||
interface SessionResponse { | ||
success: boolean; | ||
error_code?: string; | ||
user_info: Record<string, unknown>; | ||
billing: Record<string, unknown>; | ||
} | ||
|
||
export const useSessionStore = defineStore('session', () => { | ||
const sessionInfo = ref<Record<string, unknown>>({}); | ||
const isValid = ref(false); | ||
|
||
async function startSession() { | ||
try { | ||
const response = await fetch('/api/user/session'); | ||
const data: SessionResponse = await response.json(); | ||
|
||
if (data.success) { | ||
sessionInfo.value = { ...data.user_info, ...data.billing }; | ||
isValid.value = true; | ||
} else { | ||
isValid.value = false; | ||
if (data.error_code === 'SESSION_EXPIRED') { | ||
router.push('/auth/login'); | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Session error:', error); | ||
isValid.value = false; | ||
router.push('/auth/login'); | ||
} | ||
} | ||
|
||
function getInfo(key: string): string { | ||
return (sessionInfo.value[key] as string) || ''; | ||
} | ||
|
||
function isSessionValid(): boolean { | ||
return isValid.value; | ||
} | ||
|
||
return { | ||
sessionInfo, | ||
isValid, | ||
startSession, | ||
getInfo, | ||
isSessionValid, | ||
}; | ||
}); |
Oops, something went wrong.