Skip to content

Commit

Permalink
remove redundancy in api calling (fossasia#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
cweitat committed Jul 31, 2023
1 parent fe35c97 commit f744a7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/components/LoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useLoadingStore } from '@/stores/loading'
import { useAuthStore } from '@/stores/auth'
import { useApiStore } from '@/stores/api'
import StandardButton from '@/components/Shared/StandardButton.vue'
// form fields
Expand All @@ -14,7 +14,6 @@ const showError = ref(false)
// stores
const loadingStore = useLoadingStore()
const authStore = useAuthStore()
// router
const router = useRouter()
Expand All @@ -27,8 +26,7 @@ async function submitLogin() {
password: password.value
}
await authStore
.login(payload, 'auth/login')
await useApiStore().post(true, 'auth/login', payload, false)
.then(async (res) => {
localStorage.setItem('token', Object(res).access_token)
showError.value = false
Expand All @@ -39,7 +37,6 @@ async function submitLogin() {
})
.catch((err) => {
loadingStore.show = false
console.log(err)
showError.value = true
})
}
Expand All @@ -51,7 +48,7 @@ async function submitLogin() {
<h2 class="text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
Sign in to your account
</h2>
<form class="space-y-6 mt-10" @submit.prevent="submitLogin">
<form class="space-y-3 mt-10" @submit.prevent="submitLogin">
<div>
<label for="email" class="block text-sm font-medium leading-6 text-gray-900"
>Email address</label
Expand Down
11 changes: 1 addition & 10 deletions src/stores/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,5 @@ export const useAuthStore = defineStore('auth', () => {
}
}

async function login(payload, route) {
try {
const res = await useApiStore().post(true, route, payload, false)
return Object(res)
} catch (error) {
return error
}
}

return { logout, login }
return { logout }
})

0 comments on commit f744a7d

Please sign in to comment.