Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social signup / signin #120

Merged
merged 12 commits into from
Jan 23, 2024
Merged

Social signup / signin #120

merged 12 commits into from
Jan 23, 2024

Conversation

ohchanghoon
Copy link
Collaborator

Description

소셜 (카카오, 구글, 네이버) 유저 확인 / 회원가입 / 로그인

To Reviewer

첫 작업이니 미리 죄송합니다.

Reference Link

Related Issue Link

#108

API

Method Path 설명 작업(추가, 수정, 삭제)
POST /api/auth/social/check-registration 소셜 유저 프로필 유무 조회 추가
POST /api/auth/social/signup 소셜 회원가입 추가
POST /api/auth/social/signin 소셜 로그인 추가

@ohchanghoon ohchanghoon added the Feat 새로운 기능 추가 label Jan 15, 2024
@ohchanghoon ohchanghoon self-assigned this Jan 15, 2024
Copy link
Member

@rrgks6221 rrgks6221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 prettierrc를 관리하지 않아서 각 작업자들 로컬 설정을 따라가서 추후에 prettier, eslint 설정 후에 formatting 한번 돌려야할거같습니다.

@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"

export class Migrations1704208353171 implements MigrationInterface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마이그레이션을 실행할 때 클레스명을 기준으로 raw가 쌓이기떄문에 클레스명은 의미있는 이름이 들어가는게 좋습니다.(현재까지 있는 migrations raw 확인 또는 npm run migrate:show로 확인)
우선 마이그레이션 통합 작업을 진행할테니 놔두셔도 됩니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrgks6221
이거 클래스명 수동으로 변경하나요? 아니면 생성할때 명령어가 있는지 궁금합니다~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 README 에 있는 방법대로 하는데 그러면 클레스명이 파일명과 같아져요


public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE user MODIFY COLUMN login_type ENUM('email', 'KAKAO', 'GOOGLE', 'NAVER') NOT NULL DEFAULT 'email';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email 로그인은 사용하지 않기로 했으니 없어도 되지만 현재 email 값을 사용하는 raw가 있을 수 있기 때문에 놔두시고 migration 통합 때 제가 없애도록 하겠습니다.

profilePath: string | null;

@IsOptional()
majorId: number = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

majorId 1번이 경우에따라 없을수도 있습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userentity에서 필수값이라 isOptinal() 대신 isInt()로 변경해보았습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth-social.dto.ts nullable

Comment on lines 3 to 5
export interface SnsProfileBase {
sns_id: string;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 받는 필드의 interface를 정의하는게 아니라면 가급적 camelCase로 명명하는게 좋을거같아요

* @param {string} snsToken SNS에서 발급한 token
* @returns {Promise<SnsProfileBase>} SNS profile 데이터
*/
export async function getSnsProfile(loginType: string, snsToken: string): Promise<SnsProfileBase> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function getSnsProfile(loginType: string, snsToken: string): Promise<SnsProfileBase> {
export async function getSnsProfile(loginType: UserRole, snsToken: string): Promise<SnsProfileBase | null> {

지금 tsconfig 설정이 느슨해서 타입에러가 안나는데 strictNullCheck: true로 설정할 경우 에러가 나는 정의입니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserRole 대신 UserLoginType 으로 변경하겠습니다.

}),
],
controllers: [AuthSocialController],
providers: [AuthSocialService, AuthRegistrationService, AuthService],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthService를 사용하고 싶다면 AuthModule에서 AuthService를 exports 하고 AuthSocialModule에서 AuthModule을 import 하면 됩니다. 그러면 EncryptionModule, JwtModule을 제거할 수 있습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://joorrr.tistory.com/24
module imports관련 참조 링크입니당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrgks6221 @hobiJeong
좀 헷갈리는데 맞는 방식인지 검토한번 부탁드립니다!

let result: SnsProfileBase;

switch (loginType) {
case 'KAKAO': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 케이스에 지정돼있는 string 값을 enum을 사용해서 넣으면 좋겠습니다.

import { AuthRegistrationService } from "../service/auth-registration.service";
import { ApiAuthSocial } from "./auth-social.swagger";

@ApiTags('auth/social')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@ApiTags('auth/social')
@ApiTags('auth-social')

구분자는 -로 해주세요

Comment on lines 19 to 37
async checkRegistration(@Body() checkRegistrationRequestBodyDto: CheckRegistrationRequestBodyDto): Promise<boolean> {
return await this.authRegistrationService.checkUserRegistered(checkRegistrationRequestBodyDto)
}

@ApiAuthSocial.SignUp({ summary: '소셜 회원가입' })
@Post('signup')
async signUp(@Body() signUpRequestBodyDto: SignUpRequestBodyDto) {
return await this.authSocialService.signUp(signUpRequestBodyDto);
}

@ApiAuthSocial.SignIn({ summary: '소셜 로그인' })
@Post('signin')
async signIn(@Body() signInRequestBodyDto: SignInRequestBodyDto) {
return await this.authSocialService.signIn(signInRequestBodyDto);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://eslint.org/docs/latest/rules/no-return-await
이 규칙이 고려되면 좋겠습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo 예정

@@ -67,6 +67,7 @@
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/node-fetch": "^2.6.9",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http client를 어떤걸 사용할 지 내부적으로 한번 정해야겠군요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단은 유지하겠습니다

@ohchanghoon ohchanghoon force-pushed the feat/#108/social-login branch from f5f7943 to d0194be Compare January 18, 2024 14:37
@ohchanghoon ohchanghoon requested a review from rrgks6221 January 18, 2024 14:37
format: 'email',
})
@IsEmail()
@IsNullable()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsNullable 데코레이터는 null이 아닌 경우에만 유효성 검사를 진행하게 만드는 데코레이터이고 타입만 봤을땐 email, name, role은 null이 들어오면 안되는 것 같은데 이렇게 했을 때 null이 들어오면 그냥 통과될 것 같습니다.
의도하신 거라면 타입에 null도 추가해주셔야 할 것 같아용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

role을 제외하고 우선 null허용으로 작업하고 추후에 기획이 수정되면 다시 재작업하도록 하겠습니다!

Copy link
Member

@rrgks6221 rrgks6221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 일단 클라이언트측에서 사용해야하는 부분이라 먼저 내보내고 기획이 제대로 나오면 리펙토링이랑 같이 진행하는게 좋을듯하네요

@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"

export class Migrations1704208353171 implements MigrationInterface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 README 에 있는 방법대로 하는데 그러면 클레스명이 파일명과 같아져요

@ohchanghoon
Copy link
Collaborator Author

npx typeorm migration:create ./migrations/{file_name} 확인했습니다!

@ohchanghoon ohchanghoon merged commit f7d2175 into develop Jan 23, 2024
@ohchanghoon ohchanghoon deleted the feat/#108/social-login branch January 23, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feat 새로운 기능 추가
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants