Skip to content

Commit 7e52377

Browse files
committed
fix(OAuth2): fastify redirection
1 parent ed10148 commit 7e52377

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/auth/oauth/github/github.contoller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class GithubController {
1212
@Get('login')
1313
async githubLogin(@Res() res: FastifyReply) {
1414
const url = `https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_CLIENT_ID}&redirect_uri=${process.env.GITHUB_CALLBACK_URL}&scope=user:email`
15-
return res.redirect(url)
15+
return res.redirect(url, 302)
1616
}
1717

1818
@ApiTags('OAuth2-github')
@@ -26,7 +26,7 @@ export class GithubController {
2626
try {
2727
// Обрабатываем авторизацию через GitHub
2828
await this.githubOAuthService.authenticate(code, req)
29-
return res.redirect('/auth/status') // переадресация на статус
29+
return res.redirect('/auth/status', 302) // переадресация на статус
3030
} catch (error) {
3131
console.error('GitHub OAuth callback error:', error)
3232
// Обработка ошибки, если что-то пошло не так

src/auth/oauth/google/google.contoller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class OAuthController {
2121
@ApiOperation({ summary: 'Google login' })
2222
@Get('google/login')
2323
async handleLogin(@Res() res: FastifyReply) {
24+
console.log('Google login route hit')
2425
const baseUrl = 'https://accounts.google.com/o/oauth2/v2/auth'
2526
const params = new URLSearchParams({
2627
client_id: process.env.GOOGLE_CLIENT_ID,
@@ -30,7 +31,8 @@ export class OAuthController {
3031
})
3132

3233
const googleLoginUrl = `${baseUrl}?${params.toString()}`
33-
return res.redirect(googleLoginUrl)
34+
console.log('Redirecting to:', googleLoginUrl)
35+
return res.redirect(googleLoginUrl, 302)
3436
}
3537

3638
@ApiTags('OAuth2-google')
@@ -41,10 +43,15 @@ export class OAuthController {
4143
@Res() res: FastifyReply,
4244
@Req() req: FastifyRequest,
4345
) {
46+
console.log('Session before authentication:', req.session)
47+
4448
try {
4549
await this.googleService.authenticate(code, req)
46-
return res.redirect('/auth/status')
50+
console.log('Session after authentication:', req.session)
51+
return res.redirect('/auth/status', 302)
4752
} catch (error) {
53+
console.error('Authentication error:', error)
54+
4855
throw new HttpException(
4956
error.response?.data?.message || error.message,
5057
error.status || HttpStatus.INTERNAL_SERVER_ERROR,

0 commit comments

Comments
 (0)