Skip to content

Commit

Permalink
fix(auth): fix redirection to dashboard after login via ImplicitFLow
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Nov 9, 2018
1 parent 2bfc467 commit 6685ce9
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 163 deletions.
9 changes: 5 additions & 4 deletions apps/webapp/ngsw-config.json
Expand Up @@ -12,8 +12,7 @@
"/*.js"
],
"urls": [
"https://cdnjs.cloudflare.com/ajax/libs/trianglify/1.2.0/trianglify.min.js",
"https://www.google-analytics.com/analytics.js"
"https://cdnjs.cloudflare.com/ajax/libs/trianglify/1.2.0/trianglify.min.js"
]
}
}, {
Expand Down Expand Up @@ -59,12 +58,14 @@
{
"name": "keycloak",
"urls": [
"https://myroute-is360.a3c1.starter-us-west-1.openshiftapps.com/auth/realms/is360/**"
"https://myroute-is360.a3c1.starter-us-west-1.openshiftapps.com/auth/realms/is360/.well-known/openid-configuration",
"https://myroute-is360.a3c1.starter-us-west-1.openshiftapps.com/auth/realms/is360/protocol/openid-connect/certs",
"https://myroute-is360.a3c1.starter-us-west-1.openshiftapps.com/auth/realms/is360/protocol/openid-connect/login-status-iframe.html"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "90d"
"maxAge": "30d"
}
}
]
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/src/app/app.module.ts
Expand Up @@ -38,6 +38,7 @@ export class MyHammerConfig extends HammerGestureConfig {
initialNavigation: 'enabled',
preloadingStrategy: PreloadAllModules, // TODO: PreloadSelectedModulesList
paramsInheritanceStrategy: 'always',
// enableTracing: true, // enable to debug routing during development
// onSameUrlNavigation: 'reload'
},
),
Expand Down
9 changes: 6 additions & 3 deletions libs/auth/src/lib/auth.state.ts
@@ -1,3 +1,4 @@
import { NgZone } from '@angular/core';
import { Action, Select, Selector, State, StateContext } from '@ngxs/store';
import {
Login,
Expand Down Expand Up @@ -30,7 +31,7 @@ export interface AuthStateModel {
},
})
export class AuthState {
constructor(private authService: AuthService, private oauthService: OAuthService, private router: Router) {}
constructor(private authService: AuthService, private oauthService: OAuthService, private router: Router, private zone: NgZone) {}

@Selector()
static isLoggedIn(state: AuthStateModel) {
Expand All @@ -54,7 +55,9 @@ export class AuthState {
profile: payload,
});
this.authService.startAutoRefreshToken();
this.router.navigate(['/dashboard']);
if (getState().authMode === AuthMode.PasswordFlow) {
this.zone.run(() => this.router.navigate(['/dashboard']));
}
}

@Action([LogoutSuccess, LoginCanceled])
Expand All @@ -65,7 +68,7 @@ export class AuthState {
authMode: getState().authMode,
});
this.authService.stopAutoRefreshToken();
this.router.navigate(['/home']);
this.zone.run(() => this.router.navigate(['/home']));
}

@Action(AuthModeChanged)
Expand Down
2 changes: 1 addition & 1 deletion libs/auth/src/lib/oauth.config.ts
Expand Up @@ -35,7 +35,7 @@ export const authConfigImplicit: AuthConfig = {
sessionChecksEnabled: true,
useIdTokenHintForSilentRefresh: true,
// FIXME: use it for debugging only.
timeoutFactor: environment.production ? 0.75 : 0.01,
timeoutFactor: environment.production ? 0.75 : 0.1,
};

export const authConfigPassword: AuthConfig = {
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/lib/services/service-worker.service.ts
Expand Up @@ -16,7 +16,7 @@ export class ServiceWorkerService {
this.swUpdate.available.subscribe(event => {
// update available: ask the user to reload
const snackBarRef = this.snackBar
.open('Newer version of the app is available1', 'Refresh');
.open('Newer version of the app is available', 'Refresh');

snackBarRef.onAction().subscribe(() => {
window.location.reload(true);
Expand Down
1 change: 1 addition & 0 deletions libs/notifications/src/index.ts
@@ -1,2 +1,3 @@
export * from './lib/notifications.module';
export * from './lib/notifications.actions';
export * from './lib/notifications.service';
1 change: 0 additions & 1 deletion libs/notifications/src/lib/notifications.module.ts
Expand Up @@ -8,7 +8,6 @@ import { NotificationsService } from './notifications.service';
@NgModule({
imports: [SharedModule, NgxsModule.forFeature([NotificationsState])],
declarations: [NotificationsComponent],
providers: [NotificationsService],
exports: [NotificationsComponent],
})
export class NotificationsModule {}
4 changes: 3 additions & 1 deletion libs/notifications/src/lib/notifications.service.ts
Expand Up @@ -7,7 +7,9 @@ import { Observable } from 'rxjs';
import { catchError, finalize, map, retry } from 'rxjs/operators';
import { BrowserFeatureKey, FeatureService } from '@ngx-starter-kit/core';

@Injectable()
@Injectable({
providedIn: 'root',
})
export class NotificationsService extends EntityService<AppNotification> {
public apiBaseUrl = environment.API_BASE_URL;
readonly entityPath = 'notifications';
Expand Down

0 comments on commit 6685ce9

Please sign in to comment.