mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 15:07:46 +00:00
feat: add authentication modal component and user authentication logic
- 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.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { getTokenFromEvent, verifyToken } from '../utils/auth'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const path = event.path || event.node?.req?.url || ''
|
||||
|
||||
if (!path.startsWith('/api/admin')) return
|
||||
|
||||
const token = getTokenFromEvent(event)
|
||||
if (!token) {
|
||||
throw createError({ statusCode: 401, message: 'Chưa đăng nhập' })
|
||||
}
|
||||
|
||||
const payload = verifyToken(token)
|
||||
if (!payload) {
|
||||
throw createError({ statusCode: 401, message: 'Phiên đăng nhập hết hạn' })
|
||||
}
|
||||
|
||||
if (payload.role !== 'admin') {
|
||||
throw createError({ statusCode: 403, message: 'Không có quyền truy cập' })
|
||||
}
|
||||
|
||||
event.context.user = payload
|
||||
})
|
||||
Reference in New Issue
Block a user