refactor: remove email change functionality
This commit is contained in:
Binary file not shown.
@@ -271,50 +271,6 @@ export async function registerAuthRoutes(fastify) {
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
fastify.post('/api/me/change-email/request-code', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||
const userId = request.user.sub
|
||||
const newEmail = normalizeEmail(request.body?.newEmail)
|
||||
if (!newEmail || !newEmail.includes('@')) return reply.code(400).send({ error: 'Некорректная почта' })
|
||||
|
||||
const exists = await prisma.user.findUnique({
|
||||
where: { email: newEmail },
|
||||
})
|
||||
if (exists) return reply.code(409).send({ error: 'Эта почта уже занята' })
|
||||
|
||||
await issueEmailCode({
|
||||
email: newEmail,
|
||||
purpose: 'change_email',
|
||||
userId,
|
||||
})
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
fastify.post('/api/me/change-email/verify', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||
const userId = request.user.sub
|
||||
const newEmail = normalizeEmail(request.body?.newEmail)
|
||||
const code = String(request.body?.code || '').trim()
|
||||
if (!newEmail || !newEmail.includes('@')) return reply.code(400).send({ error: 'Некорректная почта' })
|
||||
if (!code || code.length !== 6) return reply.code(400).send({ error: 'Код должен быть из 6 цифр' })
|
||||
|
||||
const exists = await prisma.user.findUnique({
|
||||
where: { email: newEmail },
|
||||
})
|
||||
if (exists) return reply.code(409).send({ error: 'Эта почта уже занята' })
|
||||
|
||||
const ok = await verifyEmailCode({
|
||||
email: newEmail,
|
||||
purpose: 'change_email',
|
||||
code,
|
||||
userId,
|
||||
})
|
||||
if (!ok) return reply.code(401).send({ error: 'Неверный или истёкший код' })
|
||||
|
||||
const user = await prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: { email: newEmail },
|
||||
})
|
||||
return { user: mapUserForClient(user) }
|
||||
})
|
||||
|
||||
fastify.patch('/api/me/profile', { preHandler: [fastify.authenticate] }, async (request, reply) => {
|
||||
const userId = request.user.sub
|
||||
|
||||
Reference in New Issue
Block a user