Browse Source

Add option to "Stay signed in"

pull/82/head
Matthias Frey 4 years ago
committed by Thomas
parent
commit
cf4d78a8b7
  1. 8
      apps/client/src/app/components/header/header.component.ts
  2. 1
      apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html
  3. 2
      apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.module.ts
  4. 9
      apps/client/src/app/services/token-storage.service.ts

8
apps/client/src/app/components/header/header.component.ts

@ -87,7 +87,7 @@ export class HeaderComponent implements OnChanges {
public openLoginDialog(): void { public openLoginDialog(): void {
if(this.webAuthnService.isEnabled()){ if(this.webAuthnService.isEnabled()){
this.webAuthnService.verifyWebAuthn().subscribe(({ authToken }) => { this.webAuthnService.verifyWebAuthn().subscribe(({ authToken }) => {
this.setToken(authToken); this.setToken(authToken, false);
}); });
return; return;
} }
@ -114,14 +114,14 @@ export class HeaderComponent implements OnChanges {
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
) )
.subscribe(({ authToken }) => { .subscribe(({ authToken }) => {
this.setToken(authToken); this.setToken(authToken, data.staySignedIn);
}); });
} }
}); });
} }
public setToken(aToken: string) { public setToken(aToken: string, staySignedIn: boolean) {
this.tokenStorageService.saveToken(aToken); this.tokenStorageService.saveToken(aToken, staySignedIn);
this.router.navigate(['/']); this.router.navigate(['/']);
} }

1
apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.html

@ -19,6 +19,7 @@
[(ngModel)]="data.accessToken" [(ngModel)]="data.accessToken"
></textarea> ></textarea>
</mat-form-field> </mat-form-field>
<mat-checkbox [(ngModel)]="data.staySignedIn">Stay signed in</mat-checkbox>
</div> </div>
</div> </div>
<div class="float-right" mat-dialog-actions> <div class="float-right" mat-dialog-actions>

2
apps/client/src/app/components/login-with-access-token-dialog/login-with-access-token-dialog.module.ts

@ -6,6 +6,7 @@ import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatCheckboxModule} from "@angular/material/checkbox";
import { LoginWithAccessTokenDialog } from './login-with-access-token-dialog.component'; import { LoginWithAccessTokenDialog } from './login-with-access-token-dialog.component';
@ -16,6 +17,7 @@ import { LoginWithAccessTokenDialog } from './login-with-access-token-dialog.com
CommonModule, CommonModule,
FormsModule, FormsModule,
MatButtonModule, MatButtonModule,
MatCheckboxModule,
MatDialogModule, MatDialogModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,

9
apps/client/src/app/services/token-storage.service.ts

@ -11,11 +11,13 @@ export class TokenStorageService {
public constructor(private userService: UserService) {} public constructor(private userService: UserService) {}
public getToken(): string { public getToken(): string {
return window.sessionStorage.getItem(TOKEN_KEY); return window.localStorage.getItem(TOKEN_KEY) || window.sessionStorage.getItem(TOKEN_KEY);
} }
public saveToken(token: string): void { public saveToken(token: string, staySignedIn: boolean = false): void {
window.sessionStorage.removeItem(TOKEN_KEY); if (staySignedIn) {
window.localStorage.setItem(TOKEN_KEY, token);
}
window.sessionStorage.setItem(TOKEN_KEY, token); window.sessionStorage.setItem(TOKEN_KEY, token);
} }
@ -23,6 +25,7 @@ export class TokenStorageService {
const utmSource = window.sessionStorage.getItem('utm_source'); const utmSource = window.sessionStorage.getItem('utm_source');
window.sessionStorage.clear(); window.sessionStorage.clear();
window.localStorage.removeItem(TOKEN_KEY);
this.userService.remove(); this.userService.remove();

Loading…
Cancel
Save