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:
ngthanhvu
2026-07-22 04:26:58 -04:00
parent ad8d577493
commit d982449464
29 changed files with 1965 additions and 178 deletions
@@ -0,0 +1,25 @@
import { users } from '../../../database/schema'
import { eq } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
const db = useDb()
const id = Number(getRouterParam(event, 'id'))
if (!id) {
throw createError({ statusCode: 400, message: 'Thiếu ID thành viên' })
}
const existing = await db.select().from(users).where(eq(users.id, id)).limit(1)
if (!existing.length) {
throw createError({ statusCode: 404, message: 'Không tìm thấy thành viên' })
}
const currentUser = event.context.user
if (currentUser?.id === id) {
throw createError({ statusCode: 400, message: 'Không thể xoá chính mình' })
}
await db.delete(users).where(eq(users.id, id))
return { success: true, id }
})