Skip to content

Commit

Permalink
fix(auth): save mock token in local storage too
Browse files Browse the repository at this point in the history
  • Loading branch information
Syntox authored and Syntoxr committed Aug 11, 2022
1 parent d409a5d commit 5386fb9
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/app/auth/auth.mock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,6 @@ export class AuthMockService extends AuthService {
});
}

// #region mock local storage operations

protected override storeToken(token: string) {
console.log('JWT would be stored in local storage now');
this.localMockToken = token;
}

protected override readToken(): string {
console.log('JWT would be read from local storage now');
return this.localMockToken;
}

protected override deleteToken() {
console.log('JWT would be deleted from local storage now');
this.localMockToken = null;
}

// #endregion

private getMockResponse(username: string, password: string) {
if (username === this.mockUsername && password === this.mockPassword) {
return of({ token: this.mockToken }).pipe(delay(this.delay));
Expand All @@ -64,12 +45,14 @@ export class AuthMockService extends AuthService {
}

/**
* build mock token
* build 10 minute mock token
* the signature of the token is not valid, but the payload will be, which is sufficient for mock purposes
**/
private get mockToken() {
const payload = btoa(
`{"iss": "user", "exp": 69696969, "iat": ${Date.now()} }`
`{"iss": "user", "exp": ${
Date.now() / 1000 + 600
}, "iat": ${Date.now()} }`
);
return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${payload}.Mc3CM9MrTNPSX1b9sZFrEPGKdnYVVp-RjdiZd_2_J2w`;
}
Expand Down

0 comments on commit 5386fb9

Please # to comment.