Skip to content

Commit

Permalink
Merge pull request #10975 from roiLeo/feature/middleware/profile
Browse files Browse the repository at this point in the history
✨ middleware profile page redirect
  • Loading branch information
vikiival authored Sep 16, 2024
2 parents ef537f2 + dd6f4ae commit 29af785
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions middleware/redirects.global.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Prefix } from '@kodadot1/static'
import type { RouteLocationRaw } from 'vue-router'
import { createVisible, transferVisible, teleportVisible, migrateVisible } from '@/utils/config/permission.config'

export default defineNuxtRouteMiddleware((route) => {
Expand All @@ -15,36 +16,44 @@ export default defineNuxtRouteMiddleware((route) => {
}
}

let redirectValue
let redirectValue: RouteLocationRaw | null | undefined

const paths = [
{
cond: val => val === '/drops',
cond: (val: string) => val === '/drops',
replaceValue: '/ahp/drops',
},
{
cond: val =>
cond: (val: string) =>
val === `/${urlPrefix.value}/profile`,
replaceValue: () => {
const { accountId } = useAuth()
return accountId.value ? `/${urlPrefix.value}/u/${accountId.value}` : `/${urlPrefix.value}`
},
},
{
cond: (val: string) =>
val.startsWith(`/${urlPrefix.value}`) && val.endsWith('collections'),
replaceValue: () => `/${urlPrefix.value}/explore/collectibles`,
},
{
cond: val =>
cond: (val: string) =>
val.startsWith(`/${urlPrefix.value}`) && val.endsWith('gallery'),
replaceValue: () => `/${urlPrefix.value}/explore/items`,
},
{
cond: val => val.includes('/stmn/'),
cond: (val: string | string[]) => val.includes('/stmn/'),
replaceValue: () => window.location.href.replace('/stmn/', '/ahk/'),
},
{
cond: val => val.includes('/rmrk2/'),
cond: (val: string | string[]) => val.includes('/rmrk2/'),
replaceValue: () => window.location.href.replace('/rmrk2/', '/ksm/'),
},
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/teleport`, teleportVisible),
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/transfer`, transferVisible),
getPermissionRouteCondition((val: string) => val === '/migrate', migrateVisible),
{
cond: val => val.startsWith('/transfer'),
cond: (val: string) => val.startsWith('/transfer'),
replaceValue: () =>
window.location.href.replace('/transfer', '/ksm/transfer'),
},
Expand Down

0 comments on commit 29af785

Please sign in to comment.