Skip to content

Commit

Permalink
fix: 🐛 google login 실패 시 exception 이 처리되지 않던 문제
Browse files Browse the repository at this point in the history
- close #359
  • Loading branch information
jpham005 committed Oct 26, 2023
1 parent ee78dac commit 7d81c54
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/src/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { ConfigType } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { Cron } from '@nestjs/schedule';
import { OAuth2Client } from 'google-auth-library';
import { LoginTicket, OAuth2Client } from 'google-auth-library';
import mongoose from 'mongoose';
import { lastValueFrom } from 'rxjs';
import type { token } from 'src/auth/token/db/token.database.schema';
Expand Down Expand Up @@ -81,12 +81,9 @@ export class LoginService {
const userId = await this.getFtUser(ftCode);

await this.accountService.createIfNotExist(userId);

await this.linkAccount(userId, googleUser);

const loginUser = await this.createToken(userId);

return loginUser;
return await this.createToken(userId);
}

const linkedUser: Pick<account, 'userId'> | null =
Expand Down Expand Up @@ -250,10 +247,21 @@ export class LoginService {
async getGoogleUser(input: GoogleLoginInput): Promise<LinkableAccount> {
const oAuth2Client = new OAuth2Client();

const ticket = await oAuth2Client.verifyIdToken({
idToken: input.credential,
audience: input.clientId,
});
let ticket: LoginTicket;

try {
ticket = await oAuth2Client.verifyIdToken({
idToken: input.credential,
audience: input.clientId,
});
} catch (e) {
console.error(
'google verify id token fail',
JSON.stringify(e, null, ' '),
);

throw new BadRequestException();
}

// https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/oauth2client.ts#L1277
// https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/loginticket.ts#L26
Expand Down

0 comments on commit 7d81c54

Please sign in to comment.