added login logic

This commit is contained in:
Sockenklaus
2021-10-20 01:22:42 +02:00
parent 2896902e12
commit 60618a5eee
10 changed files with 336 additions and 205 deletions

36
src/stores/user.ts Normal file
View File

@@ -0,0 +1,36 @@
import { defineStore } from 'pinia'
import axios from 'axios'
import router from '@/router'
export const useUser = defineStore('userStore', {
state: () => {
return {
user: '',
role: '',
isLoggedIn: false
}
},
actions: {
async login(username: string, password: string) {
axios.post('http://localhost:3333/api/v1/login', {
username: username,
password: password
}).then((response) => {
console.log(response)
this.isLoggedIn = true
// this.user = response?.data?.user
// this.role = response?.data?.role
router.push({name: 'Home'})
}).catch((error) => {
console.log(error.response)
})
}
}
})