Skip to content

Commit

Permalink
Move auth outside of Axios
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Jul 11, 2024
1 parent 7885b4c commit 5c53caf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 87 deletions.
5 changes: 2 additions & 3 deletions app/assets/composables/authCheckApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ export function useCheckApi() {
const check = () => {
loading.value = true
error.value = undefined
const auth = useAuthStore()
axios
.get('/account/auth-check')
.then((response) => {
const auth = useAuthStore()
auth.setUser(response.data.user)
})
.catch((err) => {
const auth = useAuthStore()
.catch((err) => {
auth.unsetUser()
error.value = {
...err.response.data,
Expand Down
4 changes: 3 additions & 1 deletion app/assets/composables/loginApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export function useLoginApi() {
const login = (form: LoginForm) => {
loading.value = true
error.value = undefined

const auth = useAuthStore()

axios
.post('/account/login', form)
.then((response) => {
const auth = useAuthStore()
auth.setUser(response.data)
})
.catch((err) => {
Expand Down
Loading

0 comments on commit 5c53caf

Please sign in to comment.