mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 15:07:46 +00:00
- Implemented AuthModal.vue for user login and registration with form handling. - Created useAuth composable for managing user state and authentication requests. - Added admin route middleware to protect admin routes. - Developed admin login page with authentication checks. - Implemented API endpoints for user management (login, logout, fetch user, register). - Created database migrations for users table and updated movies table. - Added utility functions for password hashing and JWT token management.
24 lines
531 B
TypeScript
24 lines
531 B
TypeScript
export function useAuth() {
|
|
const user = useState<any>('auth-user', () => null)
|
|
const loading = useState('auth-loading', () => true)
|
|
|
|
async function fetchUser() {
|
|
try {
|
|
loading.value = true
|
|
const data = await $fetch('/api/auth/me')
|
|
user.value = data
|
|
} catch {
|
|
user.value = null
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function logout() {
|
|
await $fetch('/api/auth/logout', { method: 'POST' })
|
|
user.value = null
|
|
}
|
|
|
|
return { user, loading, fetchUser, logout }
|
|
}
|