feat: check link share auth from store instead
This commit is contained in:
parent
a33e2f6c00
commit
c2ffe3a9dc
@ -56,11 +56,13 @@ import {useOnline} from '@/composables/useOnline'
|
||||
import {getAuthForRoute} from '@/router'
|
||||
|
||||
import {useBaseStore} from '@/stores/base'
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const baseStore = useBaseStore()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const ready = computed(() => baseStore.ready)
|
||||
const online = useOnline()
|
||||
@ -72,7 +74,7 @@ async function load() {
|
||||
try {
|
||||
await baseStore.loadApp()
|
||||
baseStore.setReady(true)
|
||||
const redirectTo = await getAuthForRoute(route)
|
||||
const redirectTo = await getAuthForRoute(route, authStore)
|
||||
if (typeof redirectTo !== 'undefined') {
|
||||
await router.push(redirectTo)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import {saveProjectView, getProjectView} from '@/helpers/projectView'
|
||||
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
|
||||
import {getNextWeekDate} from '@/helpers/time/getNextWeekDate'
|
||||
import {setTitle} from '@/helpers/setTitle'
|
||||
import {getToken} from '@/helpers/auth'
|
||||
import {LINK_SHARE_HASH_PREFIX} from '@/constants/linkShareHash'
|
||||
|
||||
import {useProjectStore} from '@/stores/projects'
|
||||
@ -444,8 +443,7 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
export async function getAuthForRoute(route: RouteLocation) {
|
||||
const authStore = useAuthStore()
|
||||
export async function getAuthForRoute(to: RouteLocation, authStore) {
|
||||
if (authStore.authUser || authStore.authLinkShare) {
|
||||
return
|
||||
}
|
||||
@ -466,31 +464,32 @@ export async function getAuthForRoute(route: RouteLocation) {
|
||||
'user.register',
|
||||
'link-share.auth',
|
||||
'openid.auth',
|
||||
].includes(route.name as string) &&
|
||||
].includes(to.name as string) &&
|
||||
localStorage.getItem('passwordResetToken') === null &&
|
||||
localStorage.getItem('emailConfirmToken') === null &&
|
||||
!(route.name === 'home' && (typeof route.query.userPasswordReset !== 'undefined' || typeof route.query.userEmailConfirm !== 'undefined'))
|
||||
!(to.name === 'home' && (typeof to.query.userPasswordReset !== 'undefined' || typeof to.query.userEmailConfirm !== 'undefined'))
|
||||
) {
|
||||
saveLastVisited(route.name as string, route.params, route.query)
|
||||
saveLastVisited(to.name as string, to.params, to.query)
|
||||
return {name: 'user.login'}
|
||||
}
|
||||
|
||||
if(localStorage.getItem('passwordResetToken') !== null && route.name !== 'user.password-reset.reset') {
|
||||
if(localStorage.getItem('passwordResetToken') !== null && to.name !== 'user.password-reset.reset') {
|
||||
return {name: 'user.password-reset.reset'}
|
||||
}
|
||||
|
||||
if(localStorage.getItem('emailConfirmToken') !== null && route.name !== 'user.login') {
|
||||
if(localStorage.getItem('emailConfirmToken') !== null && to.name !== 'user.login') {
|
||||
return {name: 'user.login'}
|
||||
}
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from) => {
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if(from.hash && from.hash.startsWith(LINK_SHARE_HASH_PREFIX)) {
|
||||
to.hash = from.hash
|
||||
}
|
||||
|
||||
if (to.hash.startsWith(linkShareHashPrefix) && getToken() === null) {
|
||||
if (to.hash.startsWith(LINK_SHARE_HASH_PREFIX) && !authStore.authLinkShare) {
|
||||
saveLastVisited(to.name as string, to.params, to.query)
|
||||
return {
|
||||
name: 'link-share.auth',
|
||||
@ -499,8 +498,8 @@ router.beforeEach(async (to, from) => {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const newRoute = await getAuthForRoute(to)
|
||||
|
||||
const newRoute = await getAuthForRoute(to, authStore)
|
||||
if(newRoute) {
|
||||
return {
|
||||
...newRoute,
|
||||
|
Loading…
x
Reference in New Issue
Block a user