Skip to content

Commit

Permalink
fix: login redirect was not handling hash
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwylde committed Sep 5, 2024
1 parent afe8075 commit 14af741
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
23 changes: 17 additions & 6 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router'
import { createRouter, createWebHistory, RouteLocationNormalized } from 'vue-router'
import { storeToRefs } from 'pinia'

import { session } from '@/services'
Expand Down Expand Up @@ -224,7 +224,9 @@ export const portalRouter = () => {
previousRoute: session.data?.to
})
) {
return next(getRedirectRouteBasedOnPath(session.data.to, from.fullPath))
const redirectRoute = getRedirectRouteBasedOnPath(session.data.to, from.fullPath)

return next(redirectRoute)
}

if (shouldRedirectToLogin({ isPublic: isPublic.value, isSessionInvalid: !sessionDoesExist, to })) {
Expand Down Expand Up @@ -258,14 +260,23 @@ export function shouldRedirectUserToPreviouslyAccessedRoute ({
isPublic,
to,
previousRoute
}: {
isPublic: boolean
to: RouteLocationNormalized
previousRoute: string
}) {
const urlSearchParams = window && new URL(window.location.href)?.searchParams

const isLoginSuccessful = urlSearchParams?.get('loginSuccess') === 'true'
const hasPreviousRoute = previousRoute !== undefined
const isNewRoute = to.fullPath !== previousRoute
const isNotAuthRoute = !isAuthRoute(to.name)

return (
!isPublic &&
urlSearchParams?.get('loginSuccess') === 'true' &&
previousRoute !== undefined &&
to.fullPath !== previousRoute &&
!isAuthRoute(to.name)
isLoginSuccessful &&
hasPreviousRoute &&
isNewRoute &&
isNotAuthRoute
)
}
16 changes: 13 additions & 3 deletions src/router/route-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useLDFeatureFlag from '@/hooks/useLDFeatureFlag'
import { ProductAction, usePermissionsStore } from '@/stores'
import { RouteLocationNormalized, RouteLocationRaw } from 'vue-router'

export const AUTH_ROUTES = {
login: true,
Expand Down Expand Up @@ -47,8 +48,17 @@ export function getRedirectRoute (redirectName, fromName) {
return redirectName !== fromName && { name: redirectName }
}

export function getRedirectRouteBasedOnPath (redirectToPath, fromPath) {
return redirectToPath !== fromPath && { path: redirectToPath }
export function getRedirectRouteBasedOnPath (redirectToPath: string, fromPath: string): RouteLocationRaw | undefined {
if (redirectToPath !== fromPath) {
const hash = redirectToPath.split('#')[1]

return {
path: redirectToPath,
hash: hash ? `#${hash}` : undefined
}
} else {
return undefined
}
}

export function removeQueryParam (queryParam) {
Expand Down Expand Up @@ -106,6 +116,6 @@ export function verifyDeveloperFulfillMetaForRoute (to) {

// Combine both checks and should be used as default one to check developer permissions

export async function shouldDeveloperAccessRoute (to, data) {
export async function shouldDeveloperAccessRoute (to: RouteLocationNormalized, data: { portalId: string; }) {
return verifyDeveloperFulfillMetaForRoute(to) && await verifyDeveloperIsAuthorizedForRoute(to, data)
}

0 comments on commit 14af741

Please sign in to comment.