Skip to content

Commit f58a6c3

Browse files
feat: update auth service, decorators, and job controller
- Update auth service with new functionality - Refactor api and field decorators - Improve job controller implementation - Update prettier configuration - Update dependencies
1 parent b283d62 commit f58a6c3

File tree

7 files changed

+277
-232
lines changed

7 files changed

+277
-232
lines changed

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 140,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,
66
"singleQuote": true,
77
"trailingComma": "es5",
8-
"bracketSpacing": true,
8+
"bracketSpacing": false,
99
"arrowParens": "always",
1010
"endOfLine": "lf",
1111
"editor.formatOnSave": true,

pnpm-lock.yaml

Lines changed: 26 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auth/auth.service.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ export class AuthService {
119119
return this.jwtService.sign(payload as any);
120120
}
121121

122+
/**
123+
* Generates a JWT refresh token for the specified user.
124+
*
125+
* @param payload - The payload containing the user identifier
126+
* @param payload.userId - The unique identifier of the user
127+
* @returns A signed JWT refresh token string
128+
*
129+
* @remarks
130+
* The refresh token is signed using:
131+
* - Secret: Environment variable `JWT_REFRESH_TOKEN_SECRET` or fallback to 'nestjsPrismaRefreshSecret'
132+
* - Expiration: Environment variable `JWT_REFRESH_EXPIRATION_TIME` or fallback to '60m'
133+
*
134+
* @private
135+
*/
122136
private generateRefreshToken(payload: { userId: number }): string {
123137
return this.jwtService.sign(
124138
payload as any,
@@ -129,6 +143,22 @@ export class AuthService {
129143
);
130144
}
131145

146+
/**
147+
* Refreshes an access token using a valid refresh token.
148+
*
149+
* Verifies the provided refresh token and generates a new set of tokens (access and refresh)
150+
* for the authenticated user.
151+
*
152+
* @param token - The JWT refresh token to verify and use for generating new tokens
153+
* @returns A new set of authentication tokens (access token and refresh token)
154+
* @throws {UnauthorizedException} When the refresh token is invalid, expired, or malformed
155+
*
156+
* @example
157+
* ```typescript
158+
* const newTokens = await authService.refreshToken(oldRefreshToken);
159+
* // Returns: { accessToken: string, refreshToken: string }
160+
* ```
161+
*/
132162
refreshToken(token: string) {
133163
try {
134164
const { userId } = this.jwtService.verify(token, {
@@ -143,6 +173,32 @@ export class AuthService {
143173
}
144174
}
145175

176+
/**
177+
* Authenticates a user using Google OAuth ID token.
178+
*
179+
* This method verifies the Google ID token using the appropriate OAuth client ID
180+
* based on the build type (development or production). If the user doesn't exist,
181+
* it creates a new user with the Google profile information. If the user exists,
182+
* it updates their profile with the latest Google information.
183+
*
184+
* @param idToken - The Google OAuth ID token to verify
185+
* @param buildType - Optional build type ('development' or undefined for production)
186+
* that determines which Google OAuth client ID to use
187+
*
188+
* @returns A Promise that resolves to a Token object containing access and refresh tokens
189+
*
190+
* @throws {UnauthorizedException} If the OAuth client ID is missing for the specified build type
191+
* @throws {UnauthorizedException} If the Google ID token is invalid
192+
* @throws {UnauthorizedException} If the email is not provided by Google
193+
* @throws {UnauthorizedException} If there's an OAuth client ID mismatch
194+
* @throws {UnauthorizedException} If Google authentication fails for any other reason
195+
*
196+
* @remarks
197+
* - Uses different Google OAuth client IDs for development and production builds
198+
* - Creates new users with role 'USER' and no password (OAuth-only authentication)
199+
* - Updates existing users' profile information (username, profile picture, Google ID, names)
200+
* - Logs authentication progress and errors for debugging purposes
201+
*/
146202
async googleAuth(idToken: string, buildType?: string): Promise<Token> {
147203
try {
148204
// Determine which client ID to use based on build type

0 commit comments

Comments
 (0)