v0.1.60 - 닉네임 중복 검증과 비밀번호 재설정 연결
This commit is contained in:
@@ -108,6 +108,16 @@ function sanitizeUser(user) {
|
||||
}
|
||||
}
|
||||
|
||||
async function findUserByNickname(nickname) {
|
||||
const [user] = await db
|
||||
.select()
|
||||
.from(users)
|
||||
.where(eq(users.nickname, nickname))
|
||||
.limit(1)
|
||||
|
||||
return user ?? null
|
||||
}
|
||||
|
||||
export async function registerAuthRoutes(app) {
|
||||
app.post('/api/auth/signup', async (request, reply) => {
|
||||
const payload = signupSchema.safeParse(request.body)
|
||||
@@ -134,6 +144,14 @@ export async function registerAuthRoutes(app) {
|
||||
})
|
||||
}
|
||||
|
||||
const existingNicknameUser = await findUserByNickname(nickname)
|
||||
|
||||
if (existingNicknameUser) {
|
||||
return reply.code(409).send({
|
||||
message: '이미 사용 중인 닉네임입니다.',
|
||||
})
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const passwordHash = await hashPassword(password)
|
||||
const [user] = await db
|
||||
@@ -266,6 +284,14 @@ export async function registerAuthRoutes(app) {
|
||||
})
|
||||
}
|
||||
|
||||
const existingNicknameUser = await findUserByNickname(payload.data.nickname)
|
||||
|
||||
if (existingNicknameUser && existingNicknameUser.id !== user.id) {
|
||||
return reply.code(409).send({
|
||||
message: '이미 사용 중인 닉네임입니다.',
|
||||
})
|
||||
}
|
||||
|
||||
const [updatedUser] = await db
|
||||
.update(users)
|
||||
.set({
|
||||
|
||||
Reference in New Issue
Block a user