Skip to content

Commit

Permalink
combine multiple isAuthRoutes functions
Browse files Browse the repository at this point in the history
  • Loading branch information
frontegg-david committed Jan 25, 2024
1 parent 847877f commit dbd5308
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
10 changes: 1 addition & 9 deletions packages/vue/src/auth/mapAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,10 @@ export const useFronteggAuthGuard = (options?: FronteggAuthGuardOptions) => {
const router = inject(routerKey) as VueRouter;
const fronteggStore = useFronteggStore() as EnhancedStore;

const isAuthRoutes = (path: string) => {
const pathname = new URL(path, window.location.origin).pathname;
const { routes } = authState;
return Object.values(routes)
.filter(route => route !== routes.authenticatedUrl)
.includes(pathname);
};

const checkGuard = () => {
const route = fronteggAuth.getCurrentRoute();

if (!isAuthRoutes(route) && !authState.isAuthenticated && !authState.isLoading) {
if (!fronteggAuth.isAuthRoutes(route) && !authState.isAuthenticated && !authState.isLoading) {
if (fronteggOptions.hostedLoginBox) {
fronteggStore.dispatch({ type: 'auth/setState', payload: { isLoading: true } });
if (redirectUrl) {
Expand Down
9 changes: 8 additions & 1 deletion packages/vue/src/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ export class FronteggAuthService implements FronteggPluginService {
route = this.router?.currentRoute?.value?.fullPath;
}

return route
return route;
};

isAuthRoutes = (path: string): boolean => {
const pathname = new URL(path, window.location.origin).pathname;
return Object.values(this.routes)
.filter(route => route != this.routes.authenticatedUrl)
.includes(pathname);
};
}
9 changes: 1 addition & 8 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,9 @@ const Frontegg: PluginObject<PluginOptions> | any = {
}
}, 10);

const isAuthRoutes = (path: string) => {
const pathname = new URL(path, window.location.origin).pathname
const { routes } = Vue.fronteggAuth;
return Object.values(routes)
.filter(route => route != routes.authenticatedUrl)
.includes(pathname);
};

const authorizedContentGuard = (_this: any) => {
if (!_this.authorizedContent || isAuthRoutes(_this.$route.path)) {
if (!_this.authorizedContent || Vue.fronteggAuth.isAuthRoutes(_this.$route.path)) {
return;
}
if (!Vue.fronteggAuth.loading && !Vue.fronteggAuth.isAuthenticated) {
Expand Down

0 comments on commit dbd5308

Please sign in to comment.