added login logic
This commit is contained in:
36
src/stores/user.ts
Normal file
36
src/stores/user.ts
Normal 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)
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user