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 { useAppStore } from 'stores/app';
|
||||
import { useUserStore } from 'stores/user';
|
||||
import {
|
||||
createRouter,
|
||||
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) => {
|
||||
if (from.name === to.name) return;
|
||||
const app = useAppStore();
|
||||
|
|
|
@ -22,16 +22,16 @@ export const useUserStore = defineStore('user', () => {
|
|||
const tokenConfig = ref(null);
|
||||
let router;
|
||||
|
||||
const loggedIn = computed(() => !!token.value);
|
||||
const storage = computed(() =>
|
||||
keepLogin.value ? localStorage : sessionStorage
|
||||
);
|
||||
const isLoggedIn = computed(() => !!storage.value.getItem(TOKEN));
|
||||
|
||||
const init = async _router => {
|
||||
router = _router;
|
||||
isGuest.value = localStorage.getItem('hederaGuest') || false;
|
||||
await getToken();
|
||||
if (!loggedIn.value) {
|
||||
if (!isLoggedIn.value) {
|
||||
const autoLoginStatus = await tryAutoLogin();
|
||||
if (!autoLoginStatus) {
|
||||
router.push({ name: 'login' });
|
||||
|
@ -285,7 +285,6 @@ export const useUserStore = defineStore('user', () => {
|
|||
watch(
|
||||
[mainUser, supplantedUser],
|
||||
() => (user.value = supplantedUser.value || mainUser.value),
|
||||
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
|
@ -300,7 +299,7 @@ export const useUserStore = defineStore('user', () => {
|
|||
intervalId,
|
||||
isCheckingToken,
|
||||
tokenConfig,
|
||||
loggedIn,
|
||||
isLoggedIn,
|
||||
storage,
|
||||
getToken,
|
||||
getTokenMultimedia,
|
||||
|
|
Loading…
Reference in New Issue