fix: close sesion in public page

This commit is contained in:
Alexandro Uc Santos
2024-04-19 20:19:25 -06:00
parent ada429b7bf
commit 18920ac2fc
4 changed files with 19 additions and 7 deletions

View File

@@ -417,7 +417,7 @@
</div> </div>
<div class="form-section"> <div class="form-section">
<div class="mb-4 mt-3"> <div class="mb-4 mt-3">
<label class="custom-label">Terminos</label> <label class="custom-label">Productos</label>
<Products <Products
v-model="formLoad.terms" v-model="formLoad.terms"
/> />

View File

@@ -155,8 +155,8 @@ const router = createRouter({
router.beforeEach( async(to, from, next) => { router.beforeEach( async(to, from, next) => {
const requiresAuth = to.matched.some(url => url.meta.requiresAuth) const requiresAuth = to.matched.some(url => url.meta.requiresAuth)
const session = localStorage.getItem('session'); if(requiresAuth === true) {
if(requiresAuth) { const session = localStorage.getItem('session');
//Comprobamos si el usuario esta authenticado //Comprobamos si el usuario esta authenticado
if(session) { if(session) {
// if(!authStore.user) { // if(!authStore.user) {

View File

@@ -64,7 +64,7 @@ export const getCompanies = async(filter) => {
export const getLoadPublic = async(id) => { export const getLoadPublic = async(id) => {
try { try {
const endpoint = `/v1/public-load-tracking/${id}`; const endpoint = `/v1/public-load-tracking/${id}`;
console.log(endpoint); // console.log(endpoint);
const {data} = await api.get(endpoint); const {data} = await api.get(endpoint);
return data; return data;
} catch (error) { } catch (error) {

View File

@@ -1,6 +1,6 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { renewToken } from '../services/auth'; import { renewToken } from '../services/auth';
import {useNotificationsStore} from './notifications'; import {useNotificationsStore} from './notifications';
import {useCompanyStore} from './company'; import {useCompanyStore} from './company';
@@ -11,6 +11,7 @@ import { updateMyUserProfile } from "../services/company";
export const useAuthStore = defineStore('auth', () => { export const useAuthStore = defineStore('auth', () => {
const router = useRouter(); const router = useRouter();
const route = useRoute();
const noty = useNotificationsStore(); const noty = useNotificationsStore();
const company = useCompanyStore(); const company = useCompanyStore();
const loadStore = useLoadsStore(); const loadStore = useLoadsStore();
@@ -19,16 +20,27 @@ export const useAuthStore = defineStore('auth', () => {
const checking = ref(false); const checking = ref(false);
const authStatus = ref('checking'); const authStatus = ref('checking');
const token = ref('') const token = ref('')
const user = ref(null) const user = ref(null);
const publicNames = [
'terms-conditions',
'notice-privacy',
'tracking-load',
'faqs',
'login',
'register',
'recovery',
'register-company',
]
onMounted( async() => { onMounted( async() => {
checkSession(); checkSession();
}); });
const checkSession = async() => { const checkSession = async() => {
const session = localStorage.getItem('session'); const session = localStorage.getItem('session');
authStatus.value = 'checking'; authStatus.value = 'checking';
if(session) { if(session && !publicNames.includes(route.name)) {
checking.value = true; checking.value = true;
const resp = await renewToken(); const resp = await renewToken();
if(resp.msg === 'success') { if(resp.msg === 'success') {