This commit is contained in:
2022-02-10 16:07:29 +00:00
parent c693625e34
commit 21dcd7837b
8 changed files with 46 additions and 38 deletions

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia'
import { useAPI } from './api';
interface State {
Token: string | null
@ -33,17 +34,18 @@ export const useSessionStore = defineStore('session', {
this.Token = x.Token;
this.Budgets = x.Budgets;
},
login(login: any) {
return fetch("/api/v1/user/login", { method: "POST", body: JSON.stringify(login) })
.then(x => x.json())
.then(x => this.loginSuccess(x));
async login(login: any) {
const api = useAPI();
const response = await api.POST("/user/login", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
},
register(login : any) {
return fetch("/api/v1/user/register", { method: "POST", body: JSON.stringify(login) })
.then(x => x.json())
.then(x => this.loginSuccess(x))
async register(login : any) {
const api = useAPI();
const response = await api.POST("/user/register", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
},
// easily reset state using `$reset`
logout() {
this.$reset()
}