Skip to content

Commit b54726b

Browse files
authored
Merge pull request #80 from CS3219-AY2425S1/ms4-evan/patch-social-oauth
Patch: Redirect page to FE after social oauth
2 parents d9b3d46 + 58aa3dd commit b54726b

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

backend/auth-service/src/app.service.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export class AppService {
154154
}
155155
}
156156

157-
public async generateResetPasswordRequest(dto: ResetPasswordRequestDto): Promise<boolean> {
157+
public async generateResetPasswordRequest(
158+
dto: ResetPasswordRequestDto,
159+
): Promise<boolean> {
158160
const user = await firstValueFrom(
159161
this.userClient.send(
160162
{
@@ -293,13 +295,13 @@ export class AppService {
293295

294296
const [accessToken, refreshToken] = await Promise.all([
295297
this.jwtService.signAsync(
296-
{
297-
sub: id,
298-
...rest,
299-
},
300-
{
301-
secret: process.env.JWT_SECRET,
302-
expiresIn: '1h', // 1 hour
298+
{
299+
sub: id,
300+
...rest,
301+
},
302+
{
303+
secret: process.env.JWT_SECRET,
304+
expiresIn: '1h', // 1 hour
303305
},
304306
),
305307
this.jwtService.signAsync(

backend/gateway-service/src/modules/auth/auth.controller.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ export class AuthController {
133133
@Public()
134134
@Get('google/callback')
135135
@ApiOkResponse({ description: 'Google auth callback successful' })
136-
async googleAuthCallback(@Query('code') code: string) {
137-
return await firstValueFrom(
138-
this.authClient.send({ cmd: 'google-auth-redirect' }, { code }),
139-
);
136+
async googleAuthCallback(@Query('code') code: string, @Res() res: Response) {
137+
const { access_token: accessToken, refresh_token: refreshToken } =
138+
await firstValueFrom(
139+
this.authClient.send({ cmd: 'google-auth-redirect' }, { code }),
140+
);
141+
142+
const redirectUrl = `${process.env.FRONTEND_URL}/oauth?accessToken=${accessToken}&refreshToken=${refreshToken}`;
143+
res.redirect(redirectUrl);
140144
}
141145

142146
@Public()
@@ -154,9 +158,13 @@ export class AuthController {
154158
@Public()
155159
@Get('github/callback')
156160
@ApiOkResponse({ description: 'Github auth callback successful' })
157-
async githubAuthCallback(@Query('code') code: string) {
158-
return await firstValueFrom(
159-
this.authClient.send({ cmd: 'github-auth-redirect' }, { code }),
160-
);
161+
async githubAuthCallback(@Query('code') code: string, @Res() res: Response) {
162+
const { access_token: accessToken, refresh_token: refreshToken } =
163+
await firstValueFrom(
164+
this.authClient.send({ cmd: 'github-auth-redirect' }, { code }),
165+
);
166+
167+
const redirectUrl = `${process.env.FRONTEND_URL}/oauth?accessToken=${accessToken}&refreshToken=${refreshToken}`;
168+
res.redirect(redirectUrl);
161169
}
162170
}

0 commit comments

Comments
 (0)