2024-02-25 19:32:53 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<div class="flex items-center justify-center h-screen">
|
|
|
|
<form
|
|
|
|
v-if="validPayload"
|
|
|
|
class="flex flex-col gap-3 sm:w-[480px] sm:bg-white/10 sm:rounded-lg p-7"
|
|
|
|
@submit.prevent="submit"
|
|
|
|
>
|
|
|
|
<h1 class="text-2xl mb-2">Set New Password</h1>
|
|
|
|
<label>
|
|
|
|
<PasswordField v-model="password" minlength="10" placeholder="New password" required />
|
|
|
|
<span class="help block mt-4">Min. 10 characters. Should be a mix of characters, numbers, and symbols.</span>
|
|
|
|
</label>
|
2024-02-25 19:32:53 +00:00
|
|
|
<div>
|
|
|
|
<Btn :disabled="loading" type="submit">Save</Btn>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-04-23 21:01:27 +00:00
|
|
|
<script lang="ts" setup>
|
2024-02-25 19:32:53 +00:00
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { authService } from '@/services'
|
|
|
|
import { base64Decode } from '@/utils'
|
2024-04-23 11:24:29 +00:00
|
|
|
import { useErrorHandler, useMessageToaster, useRouter } from '@/composables'
|
2024-02-25 19:32:53 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
import PasswordField from '@/components/ui/form/PasswordField.vue'
|
|
|
|
import Btn from '@/components/ui/form/Btn.vue'
|
2024-02-25 19:32:53 +00:00
|
|
|
|
|
|
|
const { getRouteParam, go } = useRouter()
|
|
|
|
const { toastSuccess, toastError } = useMessageToaster()
|
|
|
|
|
|
|
|
const email = ref('')
|
|
|
|
const token = ref('')
|
|
|
|
const password = ref('')
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
const validPayload = computed(() => email.value && token.value)
|
|
|
|
|
|
|
|
try {
|
|
|
|
[email.value, token.value] = base64Decode(decodeURIComponent(getRouteParam('payload')!)).split('|')
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
2024-02-25 19:32:53 +00:00
|
|
|
toastError('Invalid reset password link.')
|
|
|
|
}
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
try {
|
|
|
|
loading.value = true
|
|
|
|
await authService.resetPassword(email.value, password.value, token.value)
|
2024-03-30 16:49:25 +00:00
|
|
|
toastSuccess('Password set.')
|
|
|
|
await authService.login(email.value, password.value)
|
|
|
|
setTimeout(() => go('/', true))
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
useErrorHandler().handleHttpError(error)
|
2024-02-25 19:32:53 +00:00
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|