Add verificationToken as a prop to let the view handle it
gitea/hedera-web/pipeline/pr-4922-vueMigration This commit looks good Details

This commit is contained in:
William Buezas 2024-07-26 10:36:48 -03:00
parent 93cc0d4286
commit 4256f45373
1 changed files with 13 additions and 6 deletions

View File

@ -8,6 +8,13 @@ import VnForm from 'src/components/common/VnForm.vue';
import { userStore as useUserStore } from 'stores/user'; import { userStore as useUserStore } from 'stores/user';
import useNotify from 'src/composables/useNotify.js'; import useNotify from 'src/composables/useNotify.js';
const props = defineProps({
verificationToken: {
type: String,
default: ''
}
});
const emit = defineEmits(['onPasswordChanged']); const emit = defineEmits(['onPasswordChanged']);
const { t } = useI18n(); const { t } = useI18n();
@ -37,16 +44,16 @@ const changePassword = async () => {
notify(t('passwordsDoNotMatch'), 'negative'); notify(t('passwordsDoNotMatch'), 'negative');
throw new Error('Passwords do not match'); throw new Error('Passwords do not match');
} }
if (userStore.token) { if (props.verificationToken) {
await changePasswordWithToken(userStore.token); await changePasswordWithToken();
} else { } else {
await changePasswordWithoutToken(); await changePasswordWithoutToken();
} }
}; };
const changePasswordWithToken = async token => { const changePasswordWithToken = async () => {
const headers = { const headers = {
Authorization: token Authorization: props.verificationToken
}; };
await api.post('VnUsers/reset-password', formData.value, { headers }); await api.post('VnUsers/reset-password', formData.value, { headers });
}; };
@ -76,7 +83,7 @@ const onPasswordChanged = async () => {
onMounted(async () => { onMounted(async () => {
getPasswordRequirements(); getPasswordRequirements();
await nextTick(); await nextTick();
if (userStore.token) { if (props.verificationToken) {
newPasswordRef.value.focus(); newPasswordRef.value.focus();
} else { } else {
oldPasswordRef.value.focus(); oldPasswordRef.value.focus();
@ -97,7 +104,7 @@ onMounted(async () => {
> >
<template #form> <template #form>
<VnInput <VnInput
v-if="!userStore.token" v-if="!verificationToken"
ref="oldPasswordRef" ref="oldPasswordRef"
v-model="formData.oldPassword" v-model="formData.oldPassword"
:label="t('oldPassword')" :label="t('oldPassword')"