Files
radicall/resources/js/Admin/store/Auth.js
T

64 lines
1.7 KiB
JavaScript

import { defineStore } from 'pinia'
import axios from "axios";
import { Inertia } from '@inertiajs/inertia'
export const useAuthStore = defineStore('AuthStore', {
state: () => ({
loginForm:{
email : '',
password : '',
remember : false,
},
registerForm:{
name : '',
email : '',
password : '',
password_confirmation : '',
},
loaderLoginForm : false,
loaderRegisterForm : false,
errorsLoginForm : [],
errorsRegisterForm : [],
}),
actions: {
login() {
this.loaderLoginForm = true;
axios.post('/admin/auth/login' , this.loginForm).then(res => {
this.resetLoginForm();
this.loaderLoginForm = false;
this.errorsLoginForm = [];
Inertia.get('/');
}).catch(error => {
this.loaderLoginForm = false;
this.errorsLoginForm = error.response.data?.errors ?? [];
});
},
register(){
this.loaderRegisterForm = true;
axios.post('/admin/auth/register' , this.registerForm).then(res => {
this.resetRegisterForm();
this.loaderRegisterForm = false;
this.errorsRegisterForm = [];
Inertia.get('/');
}).catch(error => {
this.loaderRegisterForm = false;
this.errorsRegisterForm = error.response.data?.errors ?? [];
});
},
resetLoginForm() {
this.loginForm = {
email : '',
password : '',
remember : false,
}
},
resetRegisterForm() {
this.registerForm = {
name : '',
email : '',
password : '',
password_confirmation : '',
}
},
}
})