BUG fix: login page blank
This commit is contained in:
parent
1326189b59
commit
20785a173c
|
@ -10,8 +10,6 @@ import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
|||
import { storeToRefs } from 'pinia'
|
||||
// Reset store
|
||||
import { kungalgameStoreReset } from '@/store'
|
||||
// Reset router
|
||||
import { resetRouter } from '@/router'
|
||||
|
||||
const { uid, name, moemoepoint } = storeToRefs(useKUNGalgameUserStore())
|
||||
|
||||
|
@ -42,7 +40,6 @@ const logOut = async () => {
|
|||
if (res) {
|
||||
kungalgameStoreReset()
|
||||
router.push('/login')
|
||||
resetRouter()
|
||||
Message('Logout successfully!', '登出成功', 'success')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,29 @@
|
|||
// Import rooter
|
||||
import { Router } from 'vue-router'
|
||||
// Import public routes that do not require authentication
|
||||
import { whiteList } from '../router'
|
||||
// Use user store
|
||||
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||
// Progress bar
|
||||
|
||||
import { getCurrentUserRole } from '@/utils/getCurrentUserRole'
|
||||
|
||||
import NProgress from 'nprogress'
|
||||
import '@/styles/nprogress/nprogress.scss'
|
||||
// Get the current user's role based on UID
|
||||
import { getCurrentUserRole } from '@/utils/getCurrentUserRole'
|
||||
|
||||
// Do not display the NProgress spinner
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
export const createPermission = (router: Router) => {
|
||||
router.beforeEach(async (to, from) => {
|
||||
// Start NProgress
|
||||
NProgress.start()
|
||||
// Get the current token, access token;
|
||||
// refresh token is stored on the server as HttpOnly
|
||||
|
||||
const token = useKUNGalgameUserStore().getToken()
|
||||
// Check if the route is in the whitelist
|
||||
|
||||
const isInWhitelist = whiteList.includes(to.name as string)
|
||||
// Get the required permissions for the target route
|
||||
const requiredPermissions = to.meta.permission
|
||||
? (to.meta.permission as number[])
|
||||
: [1, 2, 3, 4]
|
||||
|
||||
// If there is no token and it's not in the whitelist
|
||||
// , redirect to the login page
|
||||
if (!token && !isInWhitelist) {
|
||||
// Redirect other pages without access to the login page
|
||||
NProgress.done()
|
||||
return '/login'
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { type RouteRecordRaw, createWebHistory, createRouter } from 'vue-router'
|
||||
import { constantRoutes, whiteList } from './router'
|
||||
import { constantRoutes } from './router'
|
||||
import { asyncRoutes } from './router'
|
||||
|
||||
// Create a Vue Router instance
|
||||
|
@ -16,14 +16,4 @@ const router = createRouter({
|
|||
},
|
||||
})
|
||||
|
||||
// A function to reset the router by removing routes that are not in the whiteList
|
||||
export function resetRouter() {
|
||||
router.getRoutes().forEach((route) => {
|
||||
const { name } = route
|
||||
if (name && !whiteList.includes(name as string)) {
|
||||
router.hasRoute(name) && router.removeRoute(name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default router
|
||||
|
|
|
@ -11,8 +11,6 @@ const index: RouteRecordRaw[] = [
|
|||
{
|
||||
name: 'KUN',
|
||||
path: '',
|
||||
// Try fix nginx slash
|
||||
alias: '/',
|
||||
component: () => import('@/views/Home/KUNGalgameMainPage.vue'),
|
||||
meta: {
|
||||
title: 'home',
|
||||
|
|
|
@ -92,9 +92,6 @@ export const constantRoutes: RouteRecordRaw[] = [
|
|||
},
|
||||
]
|
||||
|
||||
const isArray = (val: any): val is object =>
|
||||
toString.call(val) === '[object Array]'
|
||||
|
||||
// 获取动态路由表
|
||||
const getAsyncRoute = (): RouteRecordRaw[] => {
|
||||
const modules = import.meta.glob('./modules/*.ts', {
|
||||
|
@ -103,7 +100,7 @@ const getAsyncRoute = (): RouteRecordRaw[] => {
|
|||
})
|
||||
const asyncRoute: RouteRecordRaw[] = []
|
||||
Object.values(modules).forEach((value) => {
|
||||
const moduleList = isArray(value)
|
||||
const moduleList = Array.isArray(value)
|
||||
? [...(value as RouteRecordRaw[])]
|
||||
: [value as RouteRecordRaw]
|
||||
asyncRoute.push(...moduleList)
|
||||
|
|
|
@ -103,13 +103,13 @@ const handleLogin = async () => {
|
|||
const res = await useKUNGalgameUserStore().login(loginForm)
|
||||
// If the request is successful, redirect to the main page
|
||||
if (res.code === 200) {
|
||||
router.push('/kun')
|
||||
Message(
|
||||
'Login Successfully! Welcome to KUN Visual Novel ~ ',
|
||||
'登陆成功!欢迎来到 鲲 Galgame ~ ',
|
||||
'success',
|
||||
5000
|
||||
)
|
||||
router.push('/kun')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue