Token changes
gitea/hedera-web/pipeline/pr-4922-vueMigration This commit looks good
Details
gitea/hedera-web/pipeline/pr-4922-vueMigration This commit looks good
Details
This commit is contained in:
parent
cfff9f7aeb
commit
cb1542937a
|
@ -1,5 +1,6 @@
|
||||||
import { route } from 'quasar/wrappers';
|
import { route } from 'quasar/wrappers';
|
||||||
import { useAppStore } from 'stores/app';
|
import { useAppStore } from 'stores/app';
|
||||||
|
import { useUserStore } from 'stores/user';
|
||||||
import {
|
import {
|
||||||
createRouter,
|
createRouter,
|
||||||
createMemoryHistory,
|
createMemoryHistory,
|
||||||
|
@ -36,6 +37,16 @@ export default route(function (/* { store, ssrContext } */) {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Router.beforeEach((to, from, next) => {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
if (!userStore.storage.getItem('token') && to.name !== 'login') {
|
||||||
|
return next({ name: 'login' });
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
Router.afterEach((to, from) => {
|
Router.afterEach((to, from) => {
|
||||||
if (from.name === to.name) return;
|
if (from.name === to.name) return;
|
||||||
const app = useAppStore();
|
const app = useAppStore();
|
||||||
|
|
|
@ -22,16 +22,16 @@ export const useUserStore = defineStore('user', () => {
|
||||||
const tokenConfig = ref(null);
|
const tokenConfig = ref(null);
|
||||||
let router;
|
let router;
|
||||||
|
|
||||||
const loggedIn = computed(() => !!token.value);
|
|
||||||
const storage = computed(() =>
|
const storage = computed(() =>
|
||||||
keepLogin.value ? localStorage : sessionStorage
|
keepLogin.value ? localStorage : sessionStorage
|
||||||
);
|
);
|
||||||
|
const isLoggedIn = computed(() => !!storage.value.getItem(TOKEN));
|
||||||
|
|
||||||
const init = async _router => {
|
const init = async _router => {
|
||||||
router = _router;
|
router = _router;
|
||||||
isGuest.value = localStorage.getItem('hederaGuest') || false;
|
isGuest.value = localStorage.getItem('hederaGuest') || false;
|
||||||
await getToken();
|
await getToken();
|
||||||
if (!loggedIn.value) {
|
if (!isLoggedIn.value) {
|
||||||
const autoLoginStatus = await tryAutoLogin();
|
const autoLoginStatus = await tryAutoLogin();
|
||||||
if (!autoLoginStatus) {
|
if (!autoLoginStatus) {
|
||||||
router.push({ name: 'login' });
|
router.push({ name: 'login' });
|
||||||
|
@ -285,7 +285,6 @@ export const useUserStore = defineStore('user', () => {
|
||||||
watch(
|
watch(
|
||||||
[mainUser, supplantedUser],
|
[mainUser, supplantedUser],
|
||||||
() => (user.value = supplantedUser.value || mainUser.value),
|
() => (user.value = supplantedUser.value || mainUser.value),
|
||||||
|
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -300,7 +299,7 @@ export const useUserStore = defineStore('user', () => {
|
||||||
intervalId,
|
intervalId,
|
||||||
isCheckingToken,
|
isCheckingToken,
|
||||||
tokenConfig,
|
tokenConfig,
|
||||||
loggedIn,
|
isLoggedIn,
|
||||||
storage,
|
storage,
|
||||||
getToken,
|
getToken,
|
||||||
getTokenMultimedia,
|
getTokenMultimedia,
|
||||||
|
|
Loading…
Reference in New Issue