Skip to content

Commit

Permalink
[FIX] createUser함수 호출위치 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leGit-y committed Oct 22, 2023
1 parent d347a50 commit 517904a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/controller/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ const kakaoLogin_getAuthorizedCode = async (req: Request, res: Response, next: N
return res.status(sc.OK).send(success(sc.OK, rm.LOGIN_SUCCESS, data.result));

}catch(error:any){

console.log(error)

//토큰이 유효하지 않은 경우
if(error.response.data.msg == "this access token does not exist"){
return res.status(sc.UNAUTHORIZED).send(fail(sc.UNAUTHORIZED, rm.INVALID_TOKEN));
}
console.log(error)
return res.status(error.response.status).send(fail(error.response.status, error.response.data.msg));

}
Expand Down
9 changes: 9 additions & 0 deletions src/repository/userRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ const findUserByKakaoId = async (KakaoId: number) => {
});
};

const findUserByAppleId = async (AppleId: number) => {
return await prisma.user.findUnique({
where: {
apple_id: AppleId
}
});
};

const createUser = async(userCreateDTO:userCreateDTO) => {
return await prisma.user.create({
data:{
Expand Down Expand Up @@ -66,5 +74,6 @@ export default {
findUserById,
createUser,
findUserByKakaoId,
findUserByAppleId,
deleteUser
};
27 changes: 23 additions & 4 deletions src/service/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const serviceLogin = async (provider:string, user:any) => {
// kakao login으로 유저 정보 갖고온 경우
if(provider == "kakao"){
const { id, kakao_account } = user;
console.log(user)

foundUser = await userService.getUserByKakaoId(id);

Expand All @@ -34,9 +35,15 @@ const serviceLogin = async (provider:string, user:any) => {
if(kakao_account.gender)
userCreateDTO.gender = kakao_account.gender


//회원가입
const createdUser = await userService.createUser(userCreateDTO);
foundUser = createdUser
isNew = true
}
}


// apple login
if(provider == "apple"){
const jwt = require("jsonwebtoken");
Expand Down Expand Up @@ -68,15 +75,27 @@ const serviceLogin = async (provider:string, user:any) => {
if(payload.sub === id && payload.aud === process.env.APPLE_CLIENT_ID){

}

foundUser = await userService.getUserByAppleId(id);
if(!foundUser){

//필수 동의만 했을 경우
userCreateDTO.AppleId = id;
// userCreateDTO.name =



//회원가입
const createdUser = await userService.createUser(userCreateDTO);
foundUser = createdUser
isNew = true
}

}

if(!foundUser){
throw new ClientException("로그인 및 회원가입 실패");
}

const createdUser = await userService.createUser(userCreateDTO);
foundUser = createdUser
isNew = true



Expand Down
6 changes: 6 additions & 0 deletions src/service/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const getUserByKakaoId =async (KakaoId: number) => {

}

const getUserByAppleId =async (AppleId: number) => {
return await userRepository.findUserByAppleId(AppleId);

}

const createUser =async (userCreateDTO:userCreateDTO) => {
const createdUser = await userRepository.createUser(userCreateDTO);
if(!createUser)
Expand All @@ -41,6 +46,7 @@ const deleteUser = async (userId: number) => {
export default{
getUserById,
getUserByKakaoId,
getUserByAppleId,
createUser,
deleteUser
}

0 comments on commit 517904a

Please sign in to comment.