Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
37
Frontend-Learner/composables/useAuth.ts
Normal file
37
Frontend-Learner/composables/useAuth.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Shared global state for current user
|
||||
const currentUser = ref({
|
||||
prefix: 'นาย',
|
||||
firstName: 'สมชาย',
|
||||
lastName: 'ใจดี',
|
||||
email: 'student@example.com',
|
||||
photoURL: '' // Set to URL if available
|
||||
})
|
||||
|
||||
export const useAuth = () => {
|
||||
const token = useCookie('auth_token', {
|
||||
maxAge: 60 * 60 * 24 * 7, // 1 week
|
||||
sameSite: 'lax',
|
||||
secure: process.env.NODE_ENV === 'production'
|
||||
})
|
||||
|
||||
const isAuthenticated = computed(() => !!token.value)
|
||||
|
||||
const login = (mockToken: string = 'demo-token') => {
|
||||
token.value = mockToken
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
token.value = null
|
||||
// Reset user photo if needed on logout
|
||||
// currentUser.value.photoURL = ''
|
||||
return navigateTo('/auth/login', { replace: true })
|
||||
}
|
||||
|
||||
return {
|
||||
isAuthenticated,
|
||||
token,
|
||||
currentUser,
|
||||
login,
|
||||
logout
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue