fix: redirect to login and validate input on password reset flow (#7521)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
Co-authored-by: Michael Genson <genson.michael@gmail.com>
This commit is contained in:
Zdenek Stursa
2026-05-10 20:37:46 +02:00
committed by GitHub
parent 8c06f49b02
commit 551a92a031
2 changed files with 32 additions and 6 deletions

View File

@@ -14,7 +14,7 @@
</v-card-title> </v-card-title>
<BaseDivider /> <BaseDivider />
<v-card-text> <v-card-text>
<v-form @submit.prevent="requestLink()"> <v-form ref="form" @submit.prevent="requestLink()">
<v-text-field <v-text-field
v-model="state.email" v-model="state.email"
:prepend-inner-icon="$globals.icons.email" :prepend-inner-icon="$globals.icons.email"
@@ -24,6 +24,7 @@
name="login" name="login"
:label="$t('user.email')" :label="$t('user.email')"
type="text" type="text"
:rules="[validators.email]"
/> />
<p class="text-center"> <p class="text-center">
{{ $t('user.forgot-password-text') }} {{ $t('user.forgot-password-text') }}
@@ -63,11 +64,15 @@
<script setup lang="ts"> <script setup lang="ts">
import { useUserApi } from "~/composables/api"; import { useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast"; import { alert } from "~/composables/use-toast";
import { validators } from "~/composables/use-validators";
import type { VForm } from "~/types/auto-forms";
definePageMeta({ definePageMeta({
layout: "basic", layout: "basic",
}); });
const form = ref<VForm | null>(null);
const state = reactive({ const state = reactive({
email: "", email: "",
loading: false, loading: false,
@@ -84,17 +89,27 @@ useSeoMeta({
const api = useUserApi(); const api = useUserApi();
async function requestLink() { async function requestLink() {
if (!form.value) {
return;
};
const { valid } = await form.value.validate();
if (!valid) {
return;
};
state.loading = true; state.loading = true;
// TODO: Fix Response to send meaningful error // TODO: Fix Response to send meaningful error
const { response } = await api.email.sendForgotPassword({ email: state.email }); const { response } = await api.email.sendForgotPassword({ email: state.email });
state.loading = false;
if (response?.status === 200) { if (response?.status === 200) {
state.loading = false;
state.error = false; state.error = false;
alert.success(i18n.t("profile.email-sent")); alert.success(i18n.t("profile.email-sent"));
await navigateTo("/login");
} }
else { else {
state.loading = false;
state.error = true; state.error = true;
alert.error(i18n.t("profile.error-sending-email")); alert.error(i18n.t("profile.error-sending-email"));
} }

View File

@@ -14,7 +14,7 @@
</v-card-title> </v-card-title>
<BaseDivider /> <BaseDivider />
<v-card-text> <v-card-text>
<v-form @submit.prevent="requestLink()"> <v-form ref="form" @submit.prevent="requestLink()">
<v-text-field <v-text-field
v-model="state.email" v-model="state.email"
:prepend-inner-icon="$globals.icons.email" :prepend-inner-icon="$globals.icons.email"
@@ -86,6 +86,7 @@ import { useUserApi } from "~/composables/api";
import { alert } from "~/composables/use-toast"; import { alert } from "~/composables/use-toast";
import { validators } from "@/composables/use-validators"; import { validators } from "@/composables/use-validators";
import { useRouteQuery } from "~/composables/use-router"; import { useRouteQuery } from "~/composables/use-router";
import type { VForm } from "~/types/auto-forms";
definePageMeta({ definePageMeta({
layout: "basic", layout: "basic",
@@ -99,6 +100,8 @@ const state = reactive({
error: false, error: false,
}); });
const form = ref<VForm | null>(null);
const i18n = useI18n(); const i18n = useI18n();
const passwordMatch = () => state.password === state.passwordConfirm || i18n.t("user.password-must-match"); const passwordMatch = () => state.password === state.passwordConfirm || i18n.t("user.password-must-match");
@@ -115,6 +118,15 @@ const token = useRouteQuery("token", "");
// API // API
const api = useUserApi(); const api = useUserApi();
async function requestLink() { async function requestLink() {
if (!form.value) {
return;
};
const { valid } = await form.value.validate();
if (!valid) {
return;
};
state.loading = true; state.loading = true;
// TODO: Fix Response to send meaningful error // TODO: Fix Response to send meaningful error
const { response } = await api.users.resetPassword({ const { response } = await api.users.resetPassword({
@@ -127,12 +139,11 @@ async function requestLink() {
state.loading = false; state.loading = false;
if (response?.status === 200) { if (response?.status === 200) {
state.loading = false;
state.error = false; state.error = false;
alert.success(i18n.t("user.password-updated")); alert.success(i18n.t("user.password-updated"));
await navigateTo("/login");
} }
else { else {
state.loading = false;
state.error = true; state.error = true;
alert.error(i18n.t("events.something-went-wrong")); alert.error(i18n.t("events.something-went-wrong"));
} }