Skip to content

Commit

Permalink
feat(auth): logout when session expires
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Nov 12, 2024
1 parent 55bcc9a commit e64d158
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/core/state/src/lib/+state/authn/authn.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export class AuthnEffects {
ofType(authnActions.signInRequest),
switchMap(({ payload }) => {
return this.authnService.signIn(payload).pipe(
tap((result) => {
console.log('Result for signin:', result);
}),
map(
({
access_token: token = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SubSink } from 'subsink';

import { NotifierService } from '@vcl/ng-vcl';

import { AppFacade } from '@console-core/state';
import { AppFacade, AuthnFacade } from '@console-core/state';

import { Notifier } from '../../utils';

Expand All @@ -31,14 +31,26 @@ export class PrivateTemplateComponent

constructor(
private readonly notifier: NotifierService,
private readonly appFacade: AppFacade
private readonly appFacade: AppFacade,
private readonly authFacade: AuthnFacade
) {
super(notifier);
this.handleNotifications(this.notifications$);
}

ngOnInit(): void {
this.subscriptions.sink = this.notifications$.subscribe();
this.subscriptions.add(this.notifications$.subscribe());
this.subscriptions.add(
this.authFacade.expiresIn$.subscribe((expiresIn) => {
// console.log("Expires in", expiresIn);
const expires = new Date(expiresIn as string);
const now = new Date();

if (now.getTime() > expires.getTime()) {
this.authFacade.signOut();
}
})
);
}

ngOnDestroy(): void {
Expand Down

0 comments on commit e64d158

Please sign in to comment.