Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: login redirect was not handling hash #553

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading