Skip to content

Commit

Permalink
Merge branch 'feature/#33-SNP-64' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondanythings committed Dec 19, 2023
2 parents ec20adb + 6362bac commit 981ddec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
13 changes: 0 additions & 13 deletions src/oauth/dtos/google.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,3 @@ export class GoogleUserInfo {
@IsString()
picture: string;
}

export class GoogleAuthResponse {
@ApiProperty({ type: () => JWT })
token: JWT;

@ApiProperty({ type: () => UserResponse })
user: UserResponse;

constructor(token: JWT, user: User) {
this.token = token;
this.user = new UserResponse(user);
}
}
9 changes: 4 additions & 5 deletions src/oauth/oauth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Param, Query, Res } from '@nestjs/common';
import { Controller, Get, Param, Post, Query, Res } from '@nestjs/common';
import { OauthService } from './oauth.service';
import { Response } from 'express';
import {
Expand All @@ -7,14 +7,13 @@ import {
ApiTags,
getSchemaPath,
} from '@nestjs/swagger';
import { GoogleAuthResponse } from './dtos/google.dto';
import { UserResponse } from 'src/users/dtos/user.dto';
import { JWT } from 'src/auth/dtos/jwt.dto';
import { ServiceProvider } from './dtos/service-provider.dto';
import { ParseExplicitEnumPipe } from 'src/common/pipes/eum.pipe';

@Controller('oauth')
@ApiExtraModels(GoogleAuthResponse, UserResponse, JWT)
@ApiExtraModels(UserResponse, JWT)
@ApiTags('Oauth API')
export class OauthController {
constructor(private readonly oauthService: OauthService) {}
Expand All @@ -32,10 +31,10 @@ export class OauthController {
@ApiOkResponse({
description: '소셜 로그인 유저 및 토큰 정보',
schema: {
$ref: getSchemaPath(GoogleAuthResponse),
$ref: getSchemaPath(JWT),
},
})
@Get(':serviceName/user')
@Post(':serviceName/user')
async getUserFromServiceProvider(
@Param('serviceName', new ParseExplicitEnumPipe(ServiceProvider))
serviceName: ServiceProvider,
Expand Down
9 changes: 6 additions & 3 deletions src/oauth/oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { AuthService } from './../auth/auth.service';
import { UserService } from './../users/user.service';
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import axios from 'axios';
import { GoogleAuthResponse, GoogleUserInfo } from './dtos/google.dto';
import { GoogleUserInfo } from './dtos/google.dto';
import { URL } from 'url';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
import { User } from 'src/users/entities/user.entity';
import { ServiceProvider } from './dtos/service-provider.dto';
import { JWT } from 'src/auth/dtos/jwt.dto';

@Injectable()
export class OauthService {
private readonly logger = new Logger(OauthService.name);
constructor(
private readonly userService: UserService,
private readonly authService: AuthService,
Expand Down Expand Up @@ -71,9 +73,10 @@ export class OauthService {
const token = this.authService.sign(user.id);
user.refresh = token.refresh;
await this.dataSource.getRepository(User).save(user);
return new GoogleAuthResponse(token, user);
return new JWT(token);
} catch (err) {
new Logger().error(err.message);
console.log(err);
this.logger.error('userFromGoogle: ' + err?.message);
throw new BadRequestException('invalid request');
}
}
Expand Down

0 comments on commit 981ddec

Please sign in to comment.