add: company info & edit company view
This commit is contained in:
@@ -3,13 +3,16 @@ import { ref, onMounted } from "vue";
|
||||
import { useRouter } from 'vue-router';
|
||||
import { renewToken } from '../services/auth';
|
||||
import {useNotificationsStore} from './notifications';
|
||||
import {useCompanyStore} from './company';
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
const router = useRouter();
|
||||
const noty = useNotificationsStore();
|
||||
const company = useCompanyStore();
|
||||
const sesion = ref('')
|
||||
const checking = ref(false);
|
||||
const authStatus = ref('checking');
|
||||
const token = ref('')
|
||||
const user = ref(null)
|
||||
|
||||
@@ -20,14 +23,15 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
const checkSession = async() => {
|
||||
const session = localStorage.getItem('session');
|
||||
authStatus.value = 'checking';
|
||||
if(session) {
|
||||
checking.value = true;
|
||||
const resp = await renewToken();
|
||||
if(resp.msg === 'success') {
|
||||
localStorage.setItem('session', resp.data.session_token);
|
||||
user.value = resp.data.user;
|
||||
sesion.value = resp.data.session_token;
|
||||
token.value = resp.data.accessToken;
|
||||
user.value = resp.data.user;
|
||||
localStorage.setItem('session', resp.data.session_token);
|
||||
checking.value = false;
|
||||
} else {
|
||||
noty.show = true;
|
||||
@@ -37,11 +41,19 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
router.push({name: 'login'});
|
||||
}
|
||||
}
|
||||
authStatus.value = 'completed';
|
||||
}
|
||||
|
||||
const authenticationPromise = new Promise((resolve) => {
|
||||
onMounted(() => {
|
||||
resolve('success');
|
||||
});
|
||||
});
|
||||
|
||||
const logout = () => {
|
||||
|
||||
localStorage.removeItem('session');
|
||||
company.clear();
|
||||
router.push({name: 'login'});
|
||||
sesion.value = '';
|
||||
token.value = '';
|
||||
@@ -53,6 +65,9 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
logout,
|
||||
token,
|
||||
user,
|
||||
checking
|
||||
checking,
|
||||
authStatus,
|
||||
checkSession,
|
||||
authenticationPromise
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user