Skip to content
Open
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
30 changes: 16 additions & 14 deletions src/app/app-router.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { AuthService } from './shared/auth-guard.service';
import { HomeComponent } from './home/home.component';
import { UserGuard } from './shared/user-guard.service';
import { UnsavedChangesGuard } from './shared/unsaved-changes.guard';

const routes: Routes = [
{
path: '',
component: HomeComponent,
loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
canActivateChild: [ UserGuard ],
canDeactivate: [ UnsavedChangesGuard ]
},
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { AuthService } from './shared/auth-guard.service';
import { HomeComponent } from './home/home.component';
import { UserGuard } from './shared/user-guard.service';
import { UnsavedChangesGuard } from './shared/unsaved-changes.guard';
import { BetaThenAuthService } from './shared/beta-then-auth-guard-service';

const routes: Routes = [
{
path: '',
component: HomeComponent,
loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
canActivate: [ BetaThenAuthService ],
canActivateChild: [ BetaThenAuthService, UserGuard ],
Comment on lines +16 to +17

Choose a reason for hiding this comment

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

P1 Badge Run auth guard after user is hydrated

The root route now runs BetaThenAuthService before UserGuard, but that guard delegates straight to AuthService.canActivateChild (shared/beta-then-auth-guard-service.ts:27-36). On a reload with an existing session, AuthService.checkUser compares the CouchDB session user to the empty UserService state (it is still unset because UserGuard has not run yet) and treats the session as invalid, opening the login dialog and cancelling navigation. This causes returning users with valid sessions to be forced to log in again; the auth check needs to run after UserGuard hydrates the user.

Useful? React with 👍 / 👎.

canDeactivate: [ UnsavedChangesGuard ]
},
{ path: 'login', loadChildren: () => import('./login/login.module').then(m => m.LoginModule), canActivate: [ AuthService ] },
{ path: '**', component: PageNotFoundComponent }
];
Expand Down
26 changes: 14 additions & 12 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ImageCropperModule } from 'ngx-image-cropper';
import { AppComponent } from './app.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { MaterialModule } from './shared/material.module';
import { environment } from '../environments/environment';
import { PlanetDialogsModule } from './shared/dialogs/planet-dialogs.module';

import { FullCalendarModule } from '@fullcalendar/angular';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { MaterialModule } from './shared/material.module';
import { environment } from '../environments/environment';
import { PlanetDialogsModule } from './shared/dialogs/planet-dialogs.module';
import { BetaThenAuthService } from './shared/beta-then-auth-guard-service';

import { FullCalendarModule } from '@fullcalendar/angular';

@NgModule({
imports: [
Expand All @@ -28,9 +29,10 @@ import { FullCalendarModule } from '@fullcalendar/angular';
? ServiceWorkerModule.register('/ngsw-worker.js')
: []
],
declarations: [
AppComponent, PageNotFoundComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
declarations: [
AppComponent, PageNotFoundComponent
],
providers: [ BetaThenAuthService ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
10 changes: 10 additions & 0 deletions src/app/shared/beta-then-auth-guard-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { AuthService } from './auth-guard.service';
import { UserService } from './user.service';
import { StateService } from './state.service';

/**
* Guard that allows beta-enabled users to skip authentication while forcing
* everyone else through the standard {@link AuthService} checks. To keep this
* guard active, ensure `betaEnabled` is set to either `off` or `user` in the
* configuration; setting it to `on` bypasses the auth flow entirely.
*/
@Injectable({
providedIn: 'root'
})
Expand All @@ -31,4 +37,8 @@ export class BetaThenAuthService {
}));
}

canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return this.canActivate(route, state);
}

}
Loading