-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fire event after new access token generated from refresh token. Updat…
…e docs
- Loading branch information
Showing
29 changed files
with
374 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/application/queries/get-current-user-by-access-token.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { IJwtPayload } from '../../domain' | ||
|
||
export class GetCurrentUserByAccessTokenQuery { | ||
public constructor(public input: IJwtPayload) {} | ||
public constructor( | ||
public accessToken: string, | ||
public jwtPayload: IJwtPayload | ||
) {} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/application/queries/get-current-user-by-refresh-token.query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export class GetCurrentUserByRefreshTokenQuery { | ||
public constructor(public token: string) {} | ||
public constructor(public refreshToken: string) {} | ||
} |
17 changes: 5 additions & 12 deletions
17
src/application/queries/handlers/get-current-user-by-access-token.query.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 10 additions & 30 deletions
40
src/application/queries/handlers/get-current-user-by-refresh-token.query.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,21 @@ | ||
import { UnauthorizedException } from '@nestjs/common' | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs' | ||
import { lastValueFrom, map } from 'rxjs' | ||
import { | ||
AuthRepository, | ||
hideRedactedFields, | ||
IAuthDefinitions, | ||
IAuthUserEntityForResponse, | ||
InjectAuthDefinitions, | ||
TokenService, | ||
} from '../../../domain' | ||
import { lastValueFrom } from 'rxjs' | ||
import { GetUserByRefreshTokenAction, IAuthResponse } from '../../../domain' | ||
import { GetCurrentUserByRefreshTokenQuery } from '../get-current-user-by-refresh-token.query' | ||
|
||
@QueryHandler(GetCurrentUserByRefreshTokenQuery) | ||
export class GetCurrentUserByRefreshTokenQueryHandler | ||
implements | ||
IQueryHandler< | ||
GetCurrentUserByRefreshTokenQuery, | ||
IAuthUserEntityForResponse | undefined | ||
> | ||
IQueryHandler<GetCurrentUserByRefreshTokenQuery, IAuthResponse | undefined> | ||
{ | ||
public constructor( | ||
@InjectAuthDefinitions() | ||
protected readonly authDefinitions: IAuthDefinitions, | ||
protected readonly authRepository: AuthRepository, | ||
protected readonly jwtService: TokenService | ||
) {} | ||
public constructor(protected readonly action: GetUserByRefreshTokenAction) {} | ||
|
||
public async execute(query: GetCurrentUserByRefreshTokenQuery) { | ||
const jwtPayload = query.token | ||
? this.jwtService.decodeRefreshToken(query.token) | ||
: undefined | ||
|
||
return jwtPayload | ||
? await lastValueFrom( | ||
this.authRepository | ||
.getAuthUserByUsername(jwtPayload.username) | ||
.pipe(map(hideRedactedFields(this.authDefinitions.redactedFields))) | ||
) | ||
: undefined | ||
try { | ||
return await lastValueFrom(this.action.handle(query)) | ||
} catch (error) { | ||
throw new UnauthorizedException() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.