UserDomain Add

This commit is contained in:
2023-10-09 15:55:58 +09:00
parent e1f2afa942
commit 76457b6667
11 changed files with 697 additions and 16 deletions

View File

@@ -0,0 +1,36 @@
import { defineStore } from 'pinia';
import { api } from 'boot/axios';
import { Router } from '../router';
export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
token: localStorage.getItem('token'),
returnUrl: ''
}),
actions: {
async login(username:string, password:string) {
const params = new URLSearchParams();
params.append('username', username);
params.append('password', password);
try{
const result = await api.post(`http://127.0.0.1:8000/api/token`,params);
console.info(result);
this.token =result.data.access_token;
localStorage.setItem('token', result.data.access_token);
Router.push(this.returnUrl || '/');
return true;
}catch(e)
{
console.info(e);
return false;
}
},
logout() {
this.token = null;
localStorage.removeItem('token');
Router.push('/login');
}
}
});