Skip to content

Commit

Permalink
refactor(#10): auth 파일 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoDora committed Sep 22, 2023
1 parent 68c6d4e commit a8adfcd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuthModule } from './auth/modules/auth.module';
import { CommentModule } from './comments/comment.module';
import { UserModule } from './users/user.module';
import { Module, NestModule } from '@nestjs/common';
Expand All @@ -13,19 +14,15 @@ import { FriendModule } from './friend/friend.module';
import { NoticeModule } from './notice/notice.module';

import * as mongoose from 'mongoose';
import { NaverStrategy } from './common/auth/naver.strategy';
import { AuthService } from './auth/auth.service';
import { AuthController } from './auth/auth.controller';
import { KakaoStrategy } from './common/auth/kakao.strategy';
import { UserRepository } from './users/repository/user.repository';

@Module({
imports: [
AuthModule,
CommentModule,
UserModule,
TypeOrmModule.forRoot({
...TypeORMconfig, // TypeORM 설정 객체 확장
synchronize: false, // DB 동기화 여부 설정
synchronize: true, // DB 동기화 여부 설정
// entities: [Image], // Image 엔티티 추가
}),
// TypeOrmModule.forFeature([Image]),
Expand All @@ -40,8 +37,10 @@ import { UserRepository } from './users/repository/user.repository';
FriendModule,
NoticeModule,
],
controllers: [AuthController,],
providers: [AuthService, UserRepository, NaverStrategy, KakaoStrategy, S3Service],
controllers: [],
providers: [
S3Service,
],
})
export class AppModule implements NestModule {
private readonly isDev: boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { AuthService } from '../auth.service';
import { Controller, Get, Req, UseGuards } from '@nestjs/common';

@Controller()
export class AuthController {
constructor(private readonly authService: AuthService) {}

@Get()
@Get('auth/naver')
@UseGuards(AuthGuard('naver'))
async naverAuth(@Req() req) {

Expand Down
13 changes: 13 additions & 0 deletions src/auth/modules/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { AuthController } from '../controllers/auth.controller';
import { AuthService } from '../auth.service';
import { UserRepository } from 'src/users/repository/user.repository';
import { NaverStrategy } from 'src/common/auth/naver.strategy';
import { KakaoStrategy } from 'src/common/auth/kakao.strategy';

@Module({
imports: [],
controllers: [AuthController],
providers: [AuthService, UserRepository, NaverStrategy, KakaoStrategy],
})
export class AuthModule {}
5 changes: 2 additions & 3 deletions src/common/auth/naver.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { VerifyCallback } from "jsonwebtoken";
import { Strategy } from 'passport-naver-v2';
import * as dotenv from 'dotenv';

Expand All @@ -16,7 +15,7 @@ export class NaverStrategy extends PassportStrategy(Strategy, 'naver') {
});
}

async validate(accessToken: string, refreshToken: string, profile: any, done: VerifyCallback) {
async validate(accessToken: string, refreshToken: string, profile: any) {
const { provider, nickname, profileImage, gender, email } = profile;

const user = {
Expand All @@ -28,6 +27,6 @@ export class NaverStrategy extends PassportStrategy(Strategy, 'naver') {
}
console.log(user);

done(null, user);
return user;
}
}

0 comments on commit a8adfcd

Please sign in to comment.