Skip to content

Commit

Permalink
Add fallback support for currentRoute.value.fullPath
Browse files Browse the repository at this point in the history
  • Loading branch information
frontegg-david committed Jan 23, 2024
1 parent 47d091e commit a005c58
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/vue/src/auth/mapAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const useLoadEntitlements = () => {
};

/**
* @returns user state
* @returns user state
*/
const useGetUserState = () => {
const authState = inject(authStateKey) as AuthState;
Expand Down Expand Up @@ -216,7 +216,8 @@ export const useFrontegg = () => {

const loginWithRedirect = () => {
// @ts-ignore
if (!fronteggAuth.router?.currentRoute.path.startsWith(authState.routes.hostedLoginRedirectUrl)) {
const path = fronteggAuth.router?.currentRoute?.path ?? fronteggAuth.router?.currentRoute?.value?.fullPath ?? "/";
if (!path.startsWith(authState.routes.hostedLoginRedirectUrl)) {
fronteggStore.dispatch({ type: 'auth/setState', payload: { isLoading: true } });
fronteggAuth.loginActions.requestHostedLoginAuthorize();
}
Expand Down Expand Up @@ -252,7 +253,11 @@ export const useFronteggAuthGuard = (options?: FronteggAuthGuardOptions) => {
};

const checkGuard = () => {
if (!isAuthRoutes(fronteggAuth.router?.currentRoute.path!) && !authState.isAuthenticated && !authState.isLoading) {

// @ts-ignore
const route = fronteggAuth.router?.currentRoute?.path ?? fronteggAuth.router?.currentRoute?.value?.fullPath ?? "/";

if (!isAuthRoutes(route) && !authState.isAuthenticated && !authState.isLoading) {
if (fronteggOptions.hostedLoginBox) {
fronteggStore.dispatch({ type: 'auth/setState', payload: { isLoading: true } });
if (redirectUrl) {
Expand Down

0 comments on commit a005c58

Please sign in to comment.