diff --git a/src/auth/oauth.controller.ts b/src/auth/oauth.controller.ts index 4507cca..855f3e1 100644 --- a/src/auth/oauth.controller.ts +++ b/src/auth/oauth.controller.ts @@ -130,13 +130,4 @@ export class OAuthController { async appleLogin(@Query('code') code: string): Promise { return this.oauthService.appleLogin(code); } - - @ApiOperation({ - summary: '카카오 로그인 요청', - description: 'accessToken을 받아 카카오 로그인을 요청합니다.', - }) - @Post('kakao') - async createOneWithKakao(@Body() kakaoLoginRequest: KakaoLoginRequest) { - return this.oauthService.createOneWithKakao(kakaoLoginRequest); - } } diff --git a/src/auth/oauth.service.ts b/src/auth/oauth.service.ts index 08ae704..09cb43f 100644 --- a/src/auth/oauth.service.ts +++ b/src/auth/oauth.service.ts @@ -34,9 +34,12 @@ export class OAuthService { ) {} // OAuth Login - async oauthLogin(email: string): Promise { + async oauthLogin(email: string, provider: PROVIDER): Promise { try { - const user: User = await this.userRepository.findOneByOrFail({ email }); + const user: User = await this.userRepository.findOneByOrFail({ + email, + provider, + }); if (user) { const payload: Payload = this.jwtService.createPayload( user.email, @@ -98,9 +101,12 @@ export class OAuthService { throw new BadRequestException('Please Agree to share your email'); } - const user = await this.userRepository.findOneByEmail(email); + const user = await this.userRepository.findOneByEmailAndProvider( + email, + PROVIDER.KAKAO, + ); if (user) { - return this.oauthLogin(user.email); + return this.oauthLogin(user.email, PROVIDER.KAKAO); } // 회원가입인 경우 기본 카테고리 생성 작업 진행 @@ -115,51 +121,25 @@ export class OAuthService { await this.userRepository.createOne(newUser); await this.categoryRepository.createDefaultCategories(newUser); - return this.oauthLogin(newUser.email); + return this.oauthLogin(newUser.email, PROVIDER.KAKAO); } catch (e) { throw e; } } - async createOneWithKakao({ authorizationToken }: KakaoLoginDto) { - const { userInfo } = - await this.oauthUtil.getKakaoUserInfo(authorizationToken); - - const email = userInfo.kakao_account.email; - if (!email) { - throw new BadRequestException('Please Agree to share your email'); - } - - const user = await this.userRepository.findOneByEmail(email); - - if (user) { - return this.oauthLogin(user.email); - } - - // 회원가입인 경우 기본 카테고리 생성 작업 진행 - const newUser = User.of({ - email, - name: userInfo.kakao_account.profile.nickname, - profileImage: userInfo.kakao_account.profile?.profile_image_url, - password: this.encodePasswordFromEmail(email, process.env.KAKAO_JS_KEY), - provider: PROVIDER.KAKAO, - }); - - await this.userRepository.createOne(newUser); - await this.categoryRepository.createDefaultCategories(newUser); - return this.oauthLogin(newUser.email); - } - // Login with Google account info async googleOauth({ email, name, picture, }: googleUserInfo): Promise { - const user = await this.userRepository.findOneByEmail(email); + const user = await this.userRepository.findOneByEmailAndProvider( + email, + PROVIDER.GOOGLE, + ); if (user) { - return this.oauthLogin(user.email); + return this.oauthLogin(user.email, PROVIDER.GOOGLE); } // 회원가입인 경우 기본 카테고리 생성 작업 진행 @@ -177,7 +157,7 @@ export class OAuthService { await this.userRepository.createOne(newUser); await this.categoryRepository.createDefaultCategories(newUser); - return this.oauthLogin(newUser.email); + return this.oauthLogin(newUser.email, PROVIDER.GOOGLE); } private encodePasswordFromEmail(email: string, key?: string): string { @@ -225,10 +205,13 @@ export class OAuthService { const { sub: id, email } = this.jwtService.decode(data.id_token); - const user = await this.userRepository.findOneByEmail(email); + const user = await this.userRepository.findOneByEmailAndProvider( + email, + PROVIDER.APPLE, + ); if (user) { - return this.oauthLogin(user.email); + return this.oauthLogin(user.email, PROVIDER.APPLE); } const newUser = User.of({ @@ -244,6 +227,6 @@ export class OAuthService { await this.userRepository.createOne(newUser); await this.categoryRepository.createDefaultCategories(newUser); - return this.oauthLogin(newUser.email); + return this.oauthLogin(newUser.email, PROVIDER.APPLE); } } diff --git a/src/categories/category.service.ts b/src/categories/category.service.ts index 3b466cf..2231b57 100644 --- a/src/categories/category.service.ts +++ b/src/categories/category.service.ts @@ -432,9 +432,10 @@ export class CategoryService { }); }); - const { title, siteName, description } = await getLinkInfo(encodeURI(link)); - - const content = await getLinkContent(link); + const [{ title, siteName, description }, content] = await Promise.all([ + getLinkInfo(encodeURI(link)), + getLinkContent(link), + ]); const question = `You are a machine tasked with auto-categorizing articles based on information obtained through web scraping. diff --git a/src/contents/util/content.util.ts b/src/contents/util/content.util.ts index 21b1b95..b1c2f91 100644 --- a/src/contents/util/content.util.ts +++ b/src/contents/util/content.util.ts @@ -26,7 +26,6 @@ class OGCrawler { this.userAgent = options.userAgent || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'; - this.maxRedirects = options.maxRedirects || 5; this.cookies = options.cookies || 'CONSENT=YES+cb; Path=/; Domain=.youtube.com'; this.proxy = options.proxy; diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index de03870..be74208 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -30,7 +30,7 @@ export class User extends CoreEntity { name: string; @ApiProperty({ example: 'ex@g.com', description: 'User Email' }) - @Column({ unique: true }) + @Column({ type: 'varchar' }) @IsEmail() email: string; diff --git a/src/users/repository/user.repository.ts b/src/users/repository/user.repository.ts index c2a508d..084bf9b 100644 --- a/src/users/repository/user.repository.ts +++ b/src/users/repository/user.repository.ts @@ -2,6 +2,7 @@ import { DataSource, Repository } from 'typeorm'; import { User } from '../entities/user.entity'; import { Injectable } from '@nestjs/common'; import { GetOrCreateAccountBodyDto } from '../dtos/get-or-create-account.dto'; +import { PROVIDER } from '../constant/provider.constant'; @Injectable() export class UserRepository extends Repository { @@ -44,6 +45,13 @@ export class UserRepository extends Repository { return this.findOne({ where: { email } }); } + async findOneByEmailAndProvider( + email: string, + provider: PROVIDER, + ): Promise { + return this.findOne({ where: { email, provider } }); + } + async createOne(user: Partial): Promise { return this.save(user); }