feat: refs #7308 remove warning
This commit is contained in:
parent
4fc9ad3f76
commit
632f7bbdeb
|
@ -3,8 +3,8 @@ import { useSession } from 'src/composables/useSession';
|
||||||
import { Router } from 'src/router';
|
import { Router } from 'src/router';
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
|
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
|
||||||
|
import { getToken, isLoggedIn } from 'src/utils/session';
|
||||||
|
|
||||||
const session = useSession();
|
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const stateQuery = useStateQueryStore();
|
const stateQuery = useStateQueryStore();
|
||||||
const baseUrl = '/api/';
|
const baseUrl = '/api/';
|
||||||
|
@ -13,7 +13,7 @@ axios.defaults.baseURL = baseUrl;
|
||||||
const axiosNoError = axios.create({ baseURL: baseUrl });
|
const axiosNoError = axios.create({ baseURL: baseUrl });
|
||||||
|
|
||||||
const onRequest = (config) => {
|
const onRequest = (config) => {
|
||||||
const token = session.getToken();
|
const token = getToken();
|
||||||
if (token.length && !config.headers.Authorization) {
|
if (token.length && !config.headers.Authorization) {
|
||||||
config.headers.Authorization = token;
|
config.headers.Authorization = token;
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,15 @@ const onResponse = (response) => {
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onResponseError = (error) => {
|
const onResponseError = async (error) => {
|
||||||
stateQuery.remove(error.config);
|
stateQuery.remove(error.config);
|
||||||
|
|
||||||
if (session.isLoggedIn() && error.response?.status === 401) {
|
if (isLoggedIn() && error.response?.status === 401) {
|
||||||
session.destroy(false);
|
await useSession().destroy(false);
|
||||||
const hash = window.location.hash;
|
const hash = window.location.hash;
|
||||||
const url = hash.slice(1);
|
const url = hash.slice(1);
|
||||||
Router.push(`/login?redirect=${url}`);
|
Router.push(`/login?redirect=${url}`);
|
||||||
} else if (!session.isLoggedIn()) {
|
} else if (!isLoggedIn()) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import axios from 'axios';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import useNotify from './useNotify';
|
import useNotify from './useNotify';
|
||||||
import { useTokenConfig } from './useTokenConfig';
|
import { useTokenConfig } from './useTokenConfig';
|
||||||
|
import { getToken, getTokenMultimedia } from 'src/utils/session';
|
||||||
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
||||||
const TOKEN = 'token';
|
const TOKEN = 'token';
|
||||||
|
|
||||||
|
@ -15,19 +16,6 @@ export function useSession() {
|
||||||
let isCheckingToken = false;
|
let isCheckingToken = false;
|
||||||
let intervalId = null;
|
let intervalId = null;
|
||||||
|
|
||||||
function getToken() {
|
|
||||||
const localToken = localStorage.getItem(TOKEN);
|
|
||||||
const sessionToken = sessionStorage.getItem(TOKEN);
|
|
||||||
|
|
||||||
return localToken || sessionToken || '';
|
|
||||||
}
|
|
||||||
function getTokenMultimedia() {
|
|
||||||
const localTokenMultimedia = localStorage.getItem(TOKEN_MULTIMEDIA);
|
|
||||||
const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA);
|
|
||||||
|
|
||||||
return localTokenMultimedia || sessionTokenMultimedia || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSession(data) {
|
function setSession(data) {
|
||||||
let keepLogin = data.keepLogin;
|
let keepLogin = data.keepLogin;
|
||||||
const storage = keepLogin ? localStorage : sessionStorage;
|
const storage = keepLogin ? localStorage : sessionStorage;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { route } from 'quasar/wrappers';
|
import { route as defineRouter } from 'quasar/wrappers';
|
||||||
import {
|
import {
|
||||||
createRouter,
|
createRouter,
|
||||||
createMemoryHistory,
|
createMemoryHistory,
|
||||||
|
@ -8,14 +8,13 @@ import {
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import { i18n } from 'src/boot/i18n';
|
import { i18n } from 'src/boot/i18n';
|
||||||
import { useState } from 'src/composables/useState';
|
import { useState } from 'src/composables/useState';
|
||||||
import { useSession } from 'src/composables/useSession';
|
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
import { useUserConfig } from 'src/composables/useUserConfig';
|
import { useUserConfig } from 'src/composables/useUserConfig';
|
||||||
import { useTokenConfig } from 'src/composables/useTokenConfig';
|
import { useTokenConfig } from 'src/composables/useTokenConfig';
|
||||||
import { useAcl } from 'src/composables/useAcl';
|
import { useAcl } from 'src/composables/useAcl';
|
||||||
|
import { isLoggedIn } from 'src/utils/session';
|
||||||
|
import { useSession } from 'src/composables/useSession';
|
||||||
|
|
||||||
const state = useState();
|
|
||||||
const session = useSession();
|
|
||||||
const { t, te } = i18n.global;
|
const { t, te } = i18n.global;
|
||||||
|
|
||||||
const createHistory = process.env.SERVER
|
const createHistory = process.env.SERVER
|
||||||
|
@ -43,11 +42,12 @@ const Router = createRouter({
|
||||||
* with the Router instance.
|
* with the Router instance.
|
||||||
*/
|
*/
|
||||||
export { Router };
|
export { Router };
|
||||||
export default route(function (/* { store, ssrContext } */) {
|
export default defineRouter(function (/* { store, ssrContext } */) {
|
||||||
|
const state = useState();
|
||||||
Router.beforeEach(async (to, from, next) => {
|
Router.beforeEach(async (to, from, next) => {
|
||||||
const { isLoggedIn } = session;
|
const session = useSession();
|
||||||
const outLayout = Router.options.routes[0].children.map((r) => r.name);
|
const outLayout = Router.options.routes[0].children.map((r) => r.name);
|
||||||
if (!isLoggedIn() && !outLayout.includes(to.name)) {
|
if (!session.isLoggedIn() && !outLayout.includes(to.name)) {
|
||||||
return next({ name: 'Login', query: { redirect: to.fullPath } });
|
return next({ name: 'Login', query: { redirect: to.fullPath } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
||||||
|
const TOKEN = 'token';
|
||||||
|
|
||||||
|
function getToken() {
|
||||||
|
const localToken = localStorage.getItem(TOKEN);
|
||||||
|
const sessionToken = sessionStorage.getItem(TOKEN);
|
||||||
|
|
||||||
|
return localToken || sessionToken || '';
|
||||||
|
}
|
||||||
|
function getTokenMultimedia() {
|
||||||
|
const localTokenMultimedia = localStorage.getItem(TOKEN_MULTIMEDIA);
|
||||||
|
const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA);
|
||||||
|
|
||||||
|
return localTokenMultimedia || sessionTokenMultimedia || '';
|
||||||
|
}
|
||||||
|
function isLoggedIn() {
|
||||||
|
const localToken = localStorage.getItem(TOKEN);
|
||||||
|
const sessionToken = sessionStorage.getItem(TOKEN);
|
||||||
|
|
||||||
|
return !!(localToken || sessionToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getToken, getTokenMultimedia, isLoggedIn };
|
Loading…
Reference in New Issue