-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthLoginForm.vue
More file actions
44 lines (39 loc) · 1.06 KB
/
AuthLoginForm.vue
File metadata and controls
44 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!-- This component handles user login functionality. -->
<script setup lang="ts">
import { useMutation } from "@tanstack/vue-query";
import authAPI from "@/api/auth";
import { useRouter } from "vue-router";
import { ElNotification } from "element-plus";
import { useAuthStore } from "@/stores/auth";
import AuthForm from "./AuthForm.vue";
import type { AxiosError } from "axios";
import type { LoginDTO } from "@seitz/shared";
const router = useRouter();
const authStore = useAuthStore();
if (authStore.currentUser) {
router.push("/");
}
const { mutate } = useMutation<void, AxiosError<Error>, LoginDTO>({
mutationFn: authAPI.logIn,
onSuccess: async () => {
authAPI.getCurrentUser().then((user) => {
authStore.currentUser = user;
router.push("/");
});
},
onError: (err) => {
ElNotification({
title: "Error",
message: err.response?.data.message ?? "",
type: "error",
});
},
});
</script>
<template>
<AuthForm
header-text="Log in to your account"
submit-text="Log In"
@submitted="mutate"
/>
</template>