From 1e8d063d0beeee6130f23adc847135b7b59f1ff6 Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Mon, 26 Aug 2024 13:42:19 +0200 Subject: [PATCH] feat(SW-307): User logout after password update --- components/Forms/Edit/Profile/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/Forms/Edit/Profile/index.tsx b/components/Forms/Edit/Profile/index.tsx index 8601bbff6..3da12068c 100644 --- a/components/Forms/Edit/Profile/index.tsx +++ b/components/Forms/Edit/Profile/index.tsx @@ -8,6 +8,7 @@ import { usePhoneInput } from "react-international-phone" import { useIntl } from "react-intl" import { type Lang, langToApiLang } from "@/constants/languages" +import { logout } from "@/constants/routes/handleAuth" import { profile } from "@/constants/routes/myPages" import { trpc } from "@/lib/trpc/client" @@ -74,6 +75,7 @@ export default function Form({ user }: EditFormProps) { const trigger = methods.trigger async function handleSubmit(data: EditProfileSchema) { + const isPasswordChanged = !!data.newPassword const response = await editProfile(data) switch (response.status) { case Status.error: @@ -87,7 +89,11 @@ export default function Form({ user }: EditFormProps) { case Status.success: toast.success(response.message) utils.user.get.invalidate() - router.push(profile[lang]) + if (isPasswordChanged) { + router.push(logout[lang] + "?redirectTo=%2Flogin%3Fuppd%3D1") + } else { + router.push(profile[lang]) + } break } }