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(core): simplified the auth guard logic to match compass goals #12

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/app/core/auth/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -35,16 +35,28 @@ export class AuthGuard {
// typically get rerouted from)

// First handle whether users are logged in. If not, go to landing, otherwise go to the hompage
if (!dbUser && (state.url !== '/' && state.url !== '/landing')) {
this.router.navigate(['/'], { queryParams: next.queryParams });
if (!dbUser) {
if (state.url !== '/' && state.url !== '/landing') {
this.router.navigate(['/'], { queryParams: next.queryParams });
return of(false);
} else {
return of(true);
}
}

// After this point user must be logged in
if (state.url === '/' || state.url === '/landing') {
this.router.navigate(['/home'], { queryParams: next.queryParams });
return of(false);
} else if (!dbUser && (state.url === '/' || state.url === '/landing')) {
return of(true);
} else if (dbUser && (state.url === '/' || state.url === '/landing')) {
}

// After this point user must be logged in
if ((state.url === '/' || state.url === '/landing')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally duplicated this block from the one right above

this.router.navigate(['/home'], { queryParams: next.queryParams });
return of(false);
}


// Make sure non-admin users can't visit admin pages and admin users can visit any page
// Note: this also means there isn't the same auto-redirection/authguard behavior for admins
if (!dbUser.isAdmin && state.url.startsWith('/admin')) {
Loading