diff --git a/client/src/pages/me/ui/sections/SettingsPage.tsx b/client/src/pages/me/ui/sections/SettingsPage.tsx index 4b62caa..df6635a 100644 --- a/client/src/pages/me/ui/sections/SettingsPage.tsx +++ b/client/src/pages/me/ui/sections/SettingsPage.tsx @@ -17,16 +17,12 @@ import { useUnit } from 'effector-react' import { useForm } from 'react-hook-form' import { AVATAR_STYLES, DEFAULT_STYLE_ID, getStyleById } from '@/shared/lib/avatar-styles' import { - $requestEmailChangeCodeError, $updateProfileError, $user, - $verifyEmailChangeError, fetchAuthMethodsFx, - requestEmailChangeCodeFx, setPasswordFx, unlinkOAuthFx, updateProfileFx, - verifyEmailChangeFx, type AuthMethod, } from '@/shared/model/auth' import { UserAvatar } from '@/shared/ui/UserAvatar' @@ -41,17 +37,8 @@ function getApiErrorMessage(error: unknown): string | null { export function SettingsPage() { const user = useUnit($user) - const pendingEmailReq = useUnit(requestEmailChangeCodeFx.pending) - const pendingEmailVerify = useUnit(verifyEmailChangeFx.pending) const pendingProfile = useUnit(updateProfileFx.pending) - const errorEmailReq = useUnit($requestEmailChangeCodeError) const errorProfile = useUnit($updateProfileError) - const errorEmailVerify = useUnit($verifyEmailChangeError) - - const emailForm = useForm<{ newEmail: string; code: string }>({ - defaultValues: { newEmail: '', code: '' }, - mode: 'onChange', - }) const profileForm = useForm<{ displayName: string }>({ defaultValues: { @@ -60,7 +47,6 @@ export function SettingsPage() { mode: 'onChange', }) - const emailErrorMsg = getApiErrorMessage(errorEmailReq) ?? getApiErrorMessage(errorEmailVerify) const profileErrorMsg = getApiErrorMessage(errorProfile) const [selectedStyle, setSelectedStyle] = useState(user?.avatarStyle || DEFAULT_STYLE_ID) @@ -136,11 +122,6 @@ export function SettingsPage() { Текущая почта: {user.email} - {emailErrorMsg && ( - - {emailErrorMsg} - - )} {profileErrorMsg && ( {profileErrorMsg} @@ -408,39 +389,6 @@ export function SettingsPage() { )} - - - - - - Смена почты - - - - - - - - - - ) diff --git a/client/src/shared/model/auth.ts b/client/src/shared/model/auth.ts index 36cf4d6..cf018fc 100644 --- a/client/src/shared/model/auth.ts +++ b/client/src/shared/model/auth.ts @@ -60,17 +60,6 @@ sample({ target: $user, }) -// ----- Email change ----- - -export const requestEmailChangeCodeFx = createEffect(async (newEmail: string) => { - await apiClient.post('me/change-email/request-code', { newEmail }) -}) - -export const verifyEmailChangeFx = createEffect(async (params: { newEmail: string; code: string }) => { - const { data } = await apiClient.post<{ user: AuthUser }>('me/change-email/verify', params) - return data.user -}) - // ----- Profile update ----- export type UpdateProfileParams = { @@ -113,17 +102,15 @@ export const unlinkOAuthFx = createEffect(async (provider: 'vk' | 'yandex') => { // ----- Error stores ----- -export const $requestEmailChangeCodeError = createErrorStore(requestEmailChangeCodeFx).$error -export const $verifyEmailChangeError = createErrorStore(verifyEmailChangeFx).$error export const $updateProfileError = createErrorStore(updateProfileFx).$error // ----- Re-exports ----- export { readStoredToken } from '@/shared/lib/persist-token' -// ----- Sync user from profile/email changes ----- +// ----- Sync user from profile changes ----- sample({ - clock: [verifyEmailChangeFx.doneData, updateProfileFx.doneData], + clock: [updateProfileFx.doneData], target: $user, }) diff --git a/server/prisma/prisma/dev.db b/server/prisma/prisma/dev.db index cda19f9..f9777dd 100644 Binary files a/server/prisma/prisma/dev.db and b/server/prisma/prisma/dev.db differ diff --git a/server/src/routes/auth.js b/server/src/routes/auth.js index 5311917..004df4c 100644 --- a/server/src/routes/auth.js +++ b/server/src/routes/auth.js @@ -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