|
|
|
|
@ -15,15 +15,21 @@ import './admin/routeMeta'
|
|
|
|
|
|
|
|
|
|
const MainLayout = () => import('../layouts/MainLayout.vue')
|
|
|
|
|
|
|
|
|
|
function participantRootRedirect() {
|
|
|
|
|
function sourceQueryFrom(to: { query?: Record<string, unknown> }): { src: string } | undefined {
|
|
|
|
|
const src = typeof to.query?.src === 'string' ? to.query.src.trim() : ''
|
|
|
|
|
return /^[A-Za-z0-9_-]{2,64}$/.test(src) ? { src } : undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function participantRootRedirect(to?: { query?: Record<string, unknown> }) {
|
|
|
|
|
const t = localStorage.getItem(TOKEN_KEY)
|
|
|
|
|
const s = localStorage.getItem(PARTICIPANT_COMPETITION_SLUG_KEY)
|
|
|
|
|
const query = to ? sourceQueryFrom(to) : undefined
|
|
|
|
|
if (s) {
|
|
|
|
|
return t
|
|
|
|
|
? { name: 'participant-apply', params: { slug: s }, replace: true as const }
|
|
|
|
|
: { name: 'participant-login', params: { slug: s }, replace: true as const }
|
|
|
|
|
? { name: 'participant-apply', params: { slug: s }, query, replace: true as const }
|
|
|
|
|
: { name: 'participant-login', params: { slug: s }, query, replace: true as const }
|
|
|
|
|
}
|
|
|
|
|
return { path: '/c', replace: true as const }
|
|
|
|
|
return { path: '/c', query, replace: true as const }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
@ -173,9 +179,13 @@ router.beforeEach(async (to) => {
|
|
|
|
|
if (to.matched.some((r) => r.meta.requiresAuth) && !participantToken) {
|
|
|
|
|
const slug = to.params.slug != null ? String(to.params.slug) : ''
|
|
|
|
|
if (slug) {
|
|
|
|
|
return { name: 'participant-login', params: { slug }, query: { redirect: to.fullPath } }
|
|
|
|
|
return {
|
|
|
|
|
name: 'participant-login',
|
|
|
|
|
params: { slug },
|
|
|
|
|
query: { redirect: to.fullPath, ...sourceQueryFrom(to) },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return { path: '/c', query: { redirect: to.fullPath } }
|
|
|
|
|
return { path: '/c', query: { redirect: to.fullPath, ...sourceQueryFrom(to) } }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (to.meta.guestOnly && participantToken) {
|
|
|
|
|
|