공개 로그인 관리자 진입 개선
This commit is contained in:
@@ -3,6 +3,7 @@ import { z } from 'zod'
|
||||
import { createError, readBody } from 'h3'
|
||||
import { getUserByEmail, touchUserActivity } from '../../repositories/member-repository'
|
||||
import { setMemberSession } from '../../utils/member-auth'
|
||||
import { setAdminSession } from '../../utils/admin-auth'
|
||||
import { getClientIp } from '../../utils/request-ip'
|
||||
import {
|
||||
assertLoginAttemptAllowed,
|
||||
@@ -18,7 +19,7 @@ const loginSchema = z.object({
|
||||
/**
|
||||
* 회원 로그인 API
|
||||
* @param {import('h3').H3Event} event - 요청 이벤트
|
||||
* @returns {Promise<{ id: string, username: string, email: string }>} 회원 정보
|
||||
* @returns {Promise<{ id: string, username: string, email: string, avatarUrl: string, isAdmin: boolean }>} 회원 정보
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const parsedBody = loginSchema.safeParse(await readBody(event))
|
||||
@@ -57,6 +58,13 @@ export default defineEventHandler(async (event) => {
|
||||
email: user.email,
|
||||
sessionVersion: user.sessionVersion
|
||||
})
|
||||
if (user.isAdmin) {
|
||||
setAdminSession(event, {
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
sessionVersion: user.sessionVersion
|
||||
})
|
||||
}
|
||||
await touchUserActivity({
|
||||
userId: user.id,
|
||||
ip
|
||||
@@ -66,6 +74,7 @@ export default defineEventHandler(async (event) => {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
avatarUrl: user.avatarUrl || ''
|
||||
avatarUrl: user.avatarUrl || '',
|
||||
isAdmin: Boolean(user.isAdmin)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { clearAdminSession } from '../../utils/admin-auth'
|
||||
import { clearMemberSession } from '../../utils/member-auth'
|
||||
|
||||
/**
|
||||
@@ -6,7 +7,7 @@ import { clearMemberSession } from '../../utils/member-auth'
|
||||
* @returns {{ ok: true }} 처리 결과
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
clearAdminSession(event)
|
||||
clearMemberSession(event)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user