태그를 관리용/일반용으로 분리하고 관리자 드래그 정렬을 추가.
댓글/회원/관리자 인증·프로필 흐름 보완과 관련 마이그레이션 및 문서를 함께 반영해 운영 동선을 안정화. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
import { createError, readBody } from 'h3'
|
||||
import { safeCompare, setAdminSession } from '../../../../utils/admin-auth'
|
||||
import bcrypt from 'bcrypt'
|
||||
import { setAdminSession } from '../../../../utils/admin-auth'
|
||||
import { getAdminUserByEmail } from '../../../../repositories/member-repository'
|
||||
import { setMemberSession } from '../../../../utils/member-auth'
|
||||
|
||||
const loginSchema = z.object({
|
||||
email: z.string().email(),
|
||||
@@ -14,7 +17,6 @@ const loginSchema = z.object({
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const parsedBody = loginSchema.safeParse(await readBody(event))
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
if (!parsedBody.success) {
|
||||
throw createError({
|
||||
@@ -25,19 +27,30 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const body = parsedBody.data
|
||||
|
||||
if (
|
||||
!safeCompare(body.email, config.adminEmail) ||
|
||||
!safeCompare(body.password, config.adminPassword)
|
||||
) {
|
||||
const adminUser = await getAdminUserByEmail(body.email)
|
||||
const passwordMatched = adminUser
|
||||
? await bcrypt.compare(body.password, adminUser.passwordHash)
|
||||
: false
|
||||
|
||||
if (!adminUser || !passwordMatched) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
message: '이메일 또는 비밀번호가 올바르지 않습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
setAdminSession(event, body.email)
|
||||
setAdminSession(event, {
|
||||
userId: adminUser.id,
|
||||
email: adminUser.email
|
||||
})
|
||||
setMemberSession(event, {
|
||||
userId: adminUser.id,
|
||||
email: adminUser.email
|
||||
})
|
||||
|
||||
return {
|
||||
email: body.email
|
||||
userId: adminUser.id,
|
||||
email: adminUser.email,
|
||||
username: adminUser.username
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { clearAdminSession } from '../../../../utils/admin-auth'
|
||||
import { clearMemberSession } from '../../../../utils/member-auth'
|
||||
|
||||
/**
|
||||
* 관리자 로그아웃 API
|
||||
@@ -7,6 +8,7 @@ import { clearAdminSession } from '../../../../utils/admin-auth'
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
clearAdminSession(event)
|
||||
clearMemberSession(event)
|
||||
|
||||
return {
|
||||
ok: true
|
||||
|
||||
@@ -3,6 +3,6 @@ import { requireAdminSession } from '../../../../utils/admin-auth'
|
||||
/**
|
||||
* 관리자 세션 조회 API
|
||||
* @param {import('h3').H3Event} event - 요청 이벤트
|
||||
* @returns {{ email: string }} 관리자 세션 정보
|
||||
* @returns {{ userId: string, email: string, role: 'admin' }} 관리자 세션 정보
|
||||
*/
|
||||
export default defineEventHandler((event) => requireAdminSession(event))
|
||||
|
||||
Reference in New Issue
Block a user