aboutsummaryrefslogtreecommitdiff
path: root/src/views/LogIn.vue
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-10-04 21:46:55 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-10-04 21:46:55 +0530
commite7c9922d36ea82a54579c1f9e6633d4ad7ad3e74 (patch)
treeead331ad3804f831dd9c2bfabf63b9fb34971f6c /src/views/LogIn.vue
parent92fb85b8afaacc4a8b5dbb41eea2d0e35eeb6862 (diff)
added login and token refreshing
Diffstat (limited to 'src/views/LogIn.vue')
-rw-r--r--src/views/LogIn.vue32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/views/LogIn.vue b/src/views/LogIn.vue
index fb9bdcd..77999f2 100644
--- a/src/views/LogIn.vue
+++ b/src/views/LogIn.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
-import { ref, toRaw } from "vue"
+import { ref, toRaw } from 'vue'
import { RouterLink, useRouter } from 'vue-router'
-import axios from "axios"
+import axios from 'axios'
import { useToast } from 'vue-toast-notification'
const toast = useToast({
@@ -11,8 +11,8 @@ const toast = useToast({
const router = useRouter()
const isLoading = ref(false)
-const email = ref("")
-const password = ref("")
+const email = ref('')
+const password = ref('')
const login = async (e) => {
e.preventDefault()
@@ -20,25 +20,25 @@ const login = async (e) => {
try {
const res = await axios.post('/auth/signin', {
- "accountname": toRaw(email.value),
- "password": toRaw(password.value),
- "method": "email"
+ accountname: toRaw(email.value),
+ password: toRaw(password.value),
+ method: 'email'
})
- localStorage.setItem("authToken", res.data.auth_token)
- localStorage.setItem("refToken", res.data.refresh_token)
+ localStorage.setItem('authToken', res.data.auth_token)
+ localStorage.setItem('refToken', res.data.refresh_token)
toast.default(`Welcome, ${res.data.data.Username}`)
- router.push({ path: "/" })
+ router.push({ path: '/' })
} catch (err) {
const statusCode = err.request.status
- switch(statusCode) {
+ switch (statusCode) {
case 401:
toast.error('Password is incorrect')
- break;
+ break
case 404:
toast.error('User does not exist')
- break;
+ break
default:
toast.error('An unhandled exception occoured. Please check logs')
}
@@ -116,7 +116,11 @@ const login = async (e) => {
</div>
-->
- <button type="submit" class="btn btn-primary btn-block mb-4" :class="{ disabled: isLoading }">
+ <button
+ type="submit"
+ class="btn btn-primary btn-block mb-4"
+ :class="{ disabled: isLoading }"
+ >
Sign In
<div v-if="isLoading" class="spinner-border spinner-border-sm ms-1" role="status">
<span class="sr-only"></span>