Skip to content

Commit 9b57984

Browse files
feat(auth): add Google OAuth callback handling
Update backend redirect to pass tokens to web API callback endpoint and add new route for token processing.
1 parent 0852666 commit 9b57984

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

apps/backend/src/auth/auth.controller.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ export class AuthController {
6767
});
6868
this.authService.setRefreshTokenCookie(res, payload.refreshToken);
6969

70-
// Redirect back to frontend dashboard
70+
// Redirect to frontend callback to set Next.js cookies
7171
const frontendUrl = this.config.corsOrigins[0]; // Usually the web frontend is first
72-
res.redirect(`${frontendUrl}/dashboard`);
72+
const redirectUrl = new URL(`${frontendUrl}/api/auth/google/callback`);
73+
redirectUrl.searchParams.set('accessToken', payload.accessToken);
74+
redirectUrl.searchParams.set('refreshToken', payload.refreshToken);
75+
76+
res.redirect(redirectUrl.toString());
7377
}
7478

7579
@Post('refresh')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { accessCookieOptions, authCookies, refreshCookieOptions } from '../../../../../src/lib/authCookies';
3+
4+
export async function GET(request: NextRequest) {
5+
const searchParams = request.nextUrl.searchParams;
6+
const accessToken = searchParams.get('accessToken');
7+
const refreshToken = searchParams.get('refreshToken');
8+
9+
const redirectUrl = new URL('/dashboard', request.url);
10+
11+
if (!accessToken || !refreshToken) {
12+
redirectUrl.pathname = '/login';
13+
redirectUrl.searchParams.set('error', 'OAuth authentication failed');
14+
return NextResponse.redirect(redirectUrl);
15+
}
16+
17+
const response = NextResponse.redirect(redirectUrl);
18+
19+
response.cookies.set(authCookies.accessToken, accessToken, accessCookieOptions);
20+
response.cookies.set(authCookies.refreshToken, refreshToken, refreshCookieOptions);
21+
22+
return response;
23+
}

0 commit comments

Comments
 (0)