Skip to content

Commit 76b4c7e

Browse files
committed
fix: resolve TypeScript errors for Vercel deployment
- Add @types/express-serve-static-core for clearCookie method - Fix passport strategy Profile types with custom interfaces - Fix jwt.strategy.ts Request type handling
1 parent 681f050 commit 76b4c7e

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/bcrypt": "^6.0.0",
5757
"@types/cookie-parser": "^1.4.10",
5858
"@types/express": "^5.0.6",
59+
"@types/express-serve-static-core": "^5.1.0",
5960
"@types/jest": "^30.0.0",
6061
"@types/ms": "^2.1.0",
6162
"@types/multer": "^2.0.0",

backend/src/auth/strategies/github.strategy.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { Injectable } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import { PassportStrategy } from '@nestjs/passport';
44

5-
import { Strategy, Profile } from 'passport-github2';
5+
import { Strategy } from 'passport-github2';
6+
7+
// GitHub OAuth profile structure
8+
interface GitHubProfile {
9+
id: string;
10+
username?: string;
11+
displayName?: string;
12+
emails?: Array<{ value: string }>;
13+
photos?: Array<{ value: string }>;
14+
}
615

716
/**
817
* GitHub App Authentication Strategy
@@ -37,17 +46,16 @@ export class GithubStrategy extends PassportStrategy(Strategy, 'github') {
3746
validate(
3847
accessToken: string,
3948
refreshToken: string,
40-
profile: Profile,
49+
profile: GitHubProfile,
4150
done: (error: Error | null, user?: Record<string, unknown>) => void,
4251
): void {
43-
const { displayName, emails, photos } = profile;
52+
const { displayName, emails, photos, id, username } = profile;
4453
// Profile values from GitHub may be null at runtime despite type definitions
4554
const user = {
4655
email: emails?.[0]?.value ?? '',
47-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
48-
fullName: displayName ?? profile.username ?? '',
56+
fullName: displayName ?? username ?? '',
4957
avatarUrl: photos?.[0]?.value ?? '',
50-
providerId: profile.id,
58+
providerId: id,
5159
accessToken,
5260
refreshToken,
5361
};

backend/src/auth/strategies/google.strategy.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@ import { Injectable } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import { PassportStrategy } from '@nestjs/passport';
44

5-
import { Strategy, VerifyCallback, Profile } from 'passport-google-oauth20';
5+
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
6+
7+
// Google OAuth profile structure
8+
interface GoogleProfile {
9+
id: string;
10+
displayName?: string;
11+
name?: {
12+
givenName?: string;
13+
familyName?: string;
14+
};
15+
emails?: Array<{ value: string; verified?: boolean }>;
16+
photos?: Array<{ value: string }>;
17+
}
618

719
@Injectable()
820
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
@@ -21,7 +33,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
2133
validate(
2234
accessToken: string,
2335
refreshToken: string,
24-
profile: Profile,
36+
profile: GoogleProfile,
2537
done: VerifyCallback,
2638
): void {
2739
const { name, emails, photos, id } = profile;

backend/src/auth/strategies/jwt.strategy.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ interface JwtPayload {
1111
role: string;
1212
}
1313

14-
interface RequestWithCookies extends Request {
15-
cookies: Record<string, string>;
16-
}
17-
1814
// Custom extractor that tries cookie first, then falls back to Bearer token
19-
const cookieExtractor = (req: RequestWithCookies): string | null => {
15+
const cookieExtractor = (req: Request): string | null => {
2016
// First try to get token from HTTP-only cookie
21-
if (req.cookies.access_token) {
22-
return req.cookies.access_token;
17+
const cookies = req.cookies as Record<string, string> | undefined;
18+
if (cookies?.access_token) {
19+
return cookies.access_token;
2320
}
2421
// Fallback to Authorization header (for API clients, testing, etc.)
2522
const authHeader = req.headers.authorization;

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)