0
1
Fork 0

Add verificationToken as a prop to let the view handle it

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