Skip to content

Commit

Permalink
fix: appleSignIn 응답 값에 따른 http code 설정 (#339)
Browse files Browse the repository at this point in the history
Co-authored-by: jeong-yong-shin <[email protected]>
  • Loading branch information
sjy982 and jeong-yong-shin authored Dec 10, 2023
1 parent a0c64c7 commit 1c17173
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
11 changes: 8 additions & 3 deletions BackEnd/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Headers, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Headers, HttpCode, HttpException, HttpStatus, Post, Res, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { RefreshTokenGuard } from './guard/bearerToken.guard';
import { SignupDto } from './dto/signup.dto';
Expand All @@ -11,11 +11,12 @@ import {
} from './dto/auth-response.dto';
import { SignInDto } from './dto/signin.dto';
import { SigninFirstResDto } from './dto/signinRedirectRes.dto';
import { Response } from 'express';

@ApiTags('Authentication')
@Controller('api/v1/auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
constructor(private readonly authService: AuthService) { }

@ApiOperation({ summary: '유저 회원가입' })
@ApiBody({ description: 'The ID of the item', type: SignupDto })
Expand Down Expand Up @@ -85,6 +86,10 @@ export class AuthController {
})
@Post('apple/signin')
async appleSignIn(@IdentityToken() token: string) {
return this.authService.appleSignIn(token);
const result = this.authService.appleSignIn(token);
// if (('isFirstLogined' in result)) {
// throw new HttpException(result, HttpStatus.CREATED);
// }
return result;
}
}
5 changes: 3 additions & 2 deletions BackEnd/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Redis } from 'ioredis';
import { AuthAppleService } from './auth-apple.service';
import { Inject, Injectable } from '@nestjs/common';
import { HttpException, Inject, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ProfilesService } from '../profiles/profiles.service';
import { UsersService } from '../users/users.service';
Expand All @@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid';
import {
InvalidTokenException,
NicknameDuplicateException,
NotFirstLoginException,
NotRefreshTokenException,
} from './exceptions/auth.exception';
import * as process from 'process';
Expand Down Expand Up @@ -134,7 +135,7 @@ export class AuthService {
provider: 'apple',
};
} else {
return this.loginUser(user.profile.publicId);
throw new NotFirstLoginException(this.loginUser(user.profile.publicId));
}
}
}
9 changes: 8 additions & 1 deletion BackEnd/src/auth/exceptions/auth.exception.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//auth와 관련된 exception을 모아둔 파일
import { HttpException } from '@nestjs/common';
import { HttpException, HttpStatus } from '@nestjs/common';

export class NicknameDuplicateException extends HttpException {
constructor() {
Expand Down Expand Up @@ -60,3 +60,10 @@ export class VerificationFailedIdentityToken extends HttpException {
super(response, httpCode);
}
}

export class NotFirstLoginException extends HttpException {
constructor(data) {
const response = { statusCode: null, message: null, data };
super(response, HttpStatus.OK);
}
}
12 changes: 8 additions & 4 deletions BackEnd/src/common/exceptionFilters/httpException.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Catch,
ExceptionFilter,
HttpException,
HttpStatus,
} from '@nestjs/common';

@Catch(HttpException)
Expand All @@ -13,13 +14,16 @@ export class HttpExceptionFilter implements ExceptionFilter {
const status = exception.getStatus();
const exceptionResponse = exception.getResponse();

const errorMessage = exceptionResponse['message'];
const statusCode = exceptionResponse['statusCode'];

let errorMessage = exceptionResponse['message'];
let statusCode = exceptionResponse['statusCode'];
let data = null;
if(status === HttpStatus.OK) {
data = exceptionResponse['data'];
}
response.status(status).json({
code: statusCode,
errorMessage,
data: null,
data,
});
}
}

0 comments on commit 1c17173

Please sign in to comment.