Skip to content

Commit

Permalink
πŸ”§ fix : merge confict μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
jinddings committed Nov 11, 2024
2 parents 5920449 + 0f58a72 commit 1fe2082
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 40 deletions.
78 changes: 78 additions & 0 deletions BE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^8.0.1",
"@nestjs/typeorm": "^10.0.2",
"@types/passport-jwt": "^4.0.1",
"@nestjs/websockets": "^10.4.7",
"@types/cookie-parser": "^1.4.7",
"@types/passport-jwt": "^4.0.1",
"axios": "^1.7.7",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cookie-parser": "^1.4.7",
"cross-env": "^7.0.3",
"docker": "^1.0.0",
"dotenv": "^16.4.5",
"fastify-swagger": "^5.1.1",
"mysql2": "^3.11.3",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-kakao": "^1.0.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"socket.io": "^4.8.1",
Expand Down
12 changes: 2 additions & 10 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@ import { StockIndexModule } from './stock/index/stock-index.module';
import { StockTopfiveModule } from './stock/topfive/stock-topfive.module';
import { KoreaInvestmentModule } from './koreaInvestment/korea-investment.module';
import { SocketModule } from './websocket/socket.module';
import { typeOrmConfig } from './configs/typeorm.config';

@Module({
imports: [
ScheduleModule.forRoot(),
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
type: 'mysql', // λ°μ΄ν„°λ² μ΄μŠ€ νƒ€μž…
host: process.env.DB_HOST,
port: 3306,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWD,
database: process.env.DB_DATABASE,
entities: [User],
synchronize: true,
}),
TypeOrmModule.forRoot(typeOrmConfig),
KoreaInvestmentModule,
AuthModule,
StockIndexModule,
Expand Down
45 changes: 42 additions & 3 deletions BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ import {
Post,
Get,
Body,
Req,
ValidationPipe,
UseGuards,
Req,
Res,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiOperation } from '@nestjs/swagger';
import { AuthService } from './auth.service';

Check failure on line 13 in BE/src/auth/auth.controller.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

'express' should be listed in the project's dependencies. Run 'npm i -S express' to add it
import { AuthCredentialsDto } from './dto/auth-credentials.dto';
import { Request, Response } from 'express';
import { ConfigService } from '@nestjs/config';

@Controller('auth')
export class AuthController {
constructor(private authService: AuthService) {}
constructor(
private authService: AuthService,
private configService: ConfigService,
) {}

@ApiOperation({ summary: 'νšŒμ› κ°€μž… API' })
@Post('/signup')
Expand All @@ -32,8 +38,41 @@ export class AuthController {

@ApiOperation({ summary: 'Token 인증 ν…ŒμŠ€νŠΈ API' })
@Get('/test')
@UseGuards(AuthGuard())
@UseGuards(AuthGuard('jwt'))
test(@Req() req: Request) {
return req;
}

@ApiOperation({ summary: 'Kakao 둜그인 API' })
@Get('/kakao')
@UseGuards(AuthGuard('kakao'))
async kakaoLogin(
@Body() authCredentialsDto: AuthCredentialsDto,
@Res() res: Response,
) {
const { accessToken, refreshToken } =
await this.authService.kakaoLoginUser(authCredentialsDto);

res.cookie('refreshToken', refreshToken, { httpOnly: true });
res.cookie('accessToken', accessToken, { httpOnly: true });
res.cookie('isRefreshToken', true, { httpOnly: true });
return res.redirect(this.configService.get<string>('CLIENT_URL'));
}

@ApiOperation({ summary: 'Refresh Token μš”μ²­ API' })
@Get('/refresh')
async refresh(@Req() req: Request, @Res() res: Response) {
const refreshToken = req.cookies['refreshToken'];
const accessToken = req.cookies['accessToken'];

if (!refreshToken || !accessToken) {
return res.status(401).send();
}

const newAccessToken = await this.authService.refreshToken(refreshToken);

Check failure on line 72 in BE/src/auth/auth.controller.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

Unsafe argument of type `any` assigned to a parameter of type `string`

res.cookie('accessToken', newAccessToken, { httpOnly: true });
res.cookie('isRefreshToken', true, { httpOnly: true });
return res.status(200).send();
}
}
21 changes: 14 additions & 7 deletions BE/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { User } from './user.entity';
import { UserRepository } from './user.repository';
import { JwtStrategy } from './jwt.strategy';
import { JwtStrategy } from './strategy/jwt.strategy';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { KakaoStrategy } from './strategy/kakao.strategy';

@Module({
imports: [
TypeOrmModule.forFeature([User]),
ConfigModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({
secret: 'Juga16',
signOptions: {
expiresIn: 3600,
},
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({

Check failure on line 20 in BE/src/auth/auth.module.ts

View workflow job for this annotation

GitHub Actions / BE-test-and-build

Async method 'useFactory' has no 'await' expression
secret: configService.get<string>('JWT_SECRET'),
signOptions: {
expiresIn: configService.get<string>('JWT_ACCESS_EXPIRATION_TIME'),
},
}),
inject: [ConfigService],
}),
],
controllers: [AuthController],
providers: [AuthService, UserRepository, JwtStrategy],
providers: [AuthService, UserRepository, JwtStrategy, KakaoStrategy],
exports: [JwtStrategy, PassportModule],
})
export class AuthModule {}
Loading

0 comments on commit 1fe2082

Please sign in to comment.