mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 17:21:35 +10:00
feat(all): upgrade to v3.4.0
This commit is contained in:
@ -21,8 +21,8 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Post('google')
|
||||
async loginWithGoogle(@Body('accessToken') googleAccessToken: string) {
|
||||
const user = await this.authService.authenticateWithGoogle(googleAccessToken);
|
||||
async loginWithGoogle(@Body('credential') credential: string) {
|
||||
const user = await this.authService.authenticateWithGoogle(credential);
|
||||
const accessToken = this.authService.getAccessToken(user.id);
|
||||
|
||||
return { user, accessToken };
|
||||
|
||||
@ -4,7 +4,7 @@ import { JwtService } from '@nestjs/jwt';
|
||||
import { SchedulerRegistry } from '@nestjs/schedule';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { randomInt } from 'crypto';
|
||||
import { google } from 'googleapis';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
|
||||
import { PostgresErrorCode } from '@/database/errorCodes.enum';
|
||||
import { CreateGoogleUserDto } from '@/users/dto/create-google-user.dto';
|
||||
@ -107,17 +107,16 @@ export class AuthService {
|
||||
return this.usersService.findById(payload.id);
|
||||
}
|
||||
|
||||
async authenticateWithGoogle(googleAccessToken: string) {
|
||||
async authenticateWithGoogle(credential: string) {
|
||||
const clientID = this.configService.get<string>('google.clientID');
|
||||
const clientSecret = this.configService.get<string>('google.clientSecret');
|
||||
|
||||
const OAuthClient = new google.auth.OAuth2(clientID, clientSecret);
|
||||
OAuthClient.setCredentials({ access_token: googleAccessToken });
|
||||
|
||||
const { email } = await OAuthClient.getTokenInfo(googleAccessToken);
|
||||
const OAuthClient = new OAuth2Client(clientID, clientSecret);
|
||||
const client = await OAuthClient.verifyIdToken({ idToken: credential });
|
||||
const userPayload = client.getPayload();
|
||||
|
||||
try {
|
||||
const user = await this.usersService.findByEmail(email);
|
||||
const user = await this.usersService.findByEmail(userPayload.email);
|
||||
|
||||
return user;
|
||||
} catch (error: any) {
|
||||
@ -125,14 +124,12 @@ export class AuthService {
|
||||
throw new HttpException(error, HttpStatus.BAD_GATEWAY);
|
||||
}
|
||||
|
||||
const UserInfoClient = google.oauth2('v2').userinfo;
|
||||
const { data } = await UserInfoClient.get({ auth: OAuthClient });
|
||||
const username = data.email.split('@')[0];
|
||||
const username = userPayload.email.split('@')[0];
|
||||
|
||||
const createUserDto: CreateGoogleUserDto = {
|
||||
name: `${data.given_name} ${data.family_name}`,
|
||||
name: `${userPayload.given_name} ${userPayload.family_name}`,
|
||||
username,
|
||||
email: data.email,
|
||||
email: userPayload.email,
|
||||
provider: 'google',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user