feat(SW-307): User logout after password update

This commit is contained in:
Hrishikesh Vaipurkar
2024-08-26 13:42:19 +02:00
parent f2a71fab8e
commit 1e8d063d0b

View File

@@ -8,6 +8,7 @@ import { usePhoneInput } from "react-international-phone"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { type Lang, langToApiLang } from "@/constants/languages" import { type Lang, langToApiLang } from "@/constants/languages"
import { logout } from "@/constants/routes/handleAuth"
import { profile } from "@/constants/routes/myPages" import { profile } from "@/constants/routes/myPages"
import { trpc } from "@/lib/trpc/client" import { trpc } from "@/lib/trpc/client"
@@ -74,6 +75,7 @@ export default function Form({ user }: EditFormProps) {
const trigger = methods.trigger const trigger = methods.trigger
async function handleSubmit(data: EditProfileSchema) { async function handleSubmit(data: EditProfileSchema) {
const isPasswordChanged = !!data.newPassword
const response = await editProfile(data) const response = await editProfile(data)
switch (response.status) { switch (response.status) {
case Status.error: case Status.error:
@@ -87,7 +89,11 @@ export default function Form({ user }: EditFormProps) {
case Status.success: case Status.success:
toast.success(response.message) toast.success(response.message)
utils.user.get.invalidate() utils.user.get.invalidate()
router.push(profile[lang]) if (isPasswordChanged) {
router.push(logout[lang] + "?redirectTo=%2Flogin%3Fuppd%3D1")
} else {
router.push(profile[lang])
}
break break
} }
} }