Something went wrong. Try again.
because I got bored of customising my CV for every job
Something went wrong. Try again.
1.2 kB · 50 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import type { User } from "@cv/core";import { UserService } from "@cv/core";import { Injectable } from "@nestjs/common";export interface RefreshTokenDto { refresh_token: string;}
export interface RefreshTokenResponse { access_token: string; expires_at: Date;}
type InternalRefreshTokenResponse = RefreshTokenResponse & { refresh_token: string;};
import type { RequestMetadata } from "@cv/core";import { TokenService } from "@cv/core";
@Injectable()export class AuthenticationService { constructor( private userService: UserService, private tokenService: TokenService, ) {}
async refreshToken( { refresh_token }: RefreshTokenDto, requestMetadata?: RequestMetadata, ): Promise<InternalRefreshTokenResponse> { const tokens = await this.tokenService.refreshTokenPair( refresh_token, requestMetadata, );
return { access_token: tokens.access_token, expires_at: tokens.expires_at, refresh_token: tokens.refresh_token, }; }
async validateUser(userId: string): Promise<User | null> { try { return await this.userService.findByIdOrFail(userId); } catch { return null; } }}