Skip to content

Commit

Permalink
Merge pull request #40 from GoogleEyes-ewha/feature/#16
Browse files Browse the repository at this point in the history
[Feature] 구글 소셜 로그인 redirect 추가
  • Loading branch information
Haewonny authored Feb 25, 2024
2 parents ac22987 + 1dc8b61 commit b31e581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.gdsc.hearo.domain.oauth.controller;

import com.gdsc.hearo.domain.member.dto.LoginResponseDto;
import com.gdsc.hearo.domain.member.entity.Member;
import com.gdsc.hearo.domain.oauth.dto.GoogleProfile;
import com.gdsc.hearo.domain.oauth.service.OauthService;
import com.gdsc.hearo.global.common.BaseException;
import com.gdsc.hearo.global.common.BaseResponse;
import com.gdsc.hearo.global.common.BaseResponseStatus;
import com.gdsc.hearo.global.security.JwtUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

@RestController
@CrossOrigin
Expand All @@ -26,20 +23,23 @@ public class OauthController {
public void socialLoginType() {
oauthService.request();
}

@GetMapping(value = "/google/callback")
public BaseResponse<?> googleLogin(@RequestParam(name = "code") String code) {
public RedirectView googleLogin(@RequestParam(name = "code") String code) {

GoogleProfile googleProfile = oauthService.requestGoogleProfile(code);
Member member = oauthService.googleLogin(googleProfile);

String accessToken = jwtUtil.createAccessToken(member.getLoginId());
String refreshToken = jwtUtil.createRefreshToken(member.getLoginId());

RedirectView redirectView = new RedirectView();

try {
GoogleProfile googleProfile = oauthService.requestGoogleProfile(code);
Member member = oauthService.googleLogin(googleProfile);
redirectView.setUrl("http://localhost:3000/login/callback?accessToken={accessToken}&refreshToken={refreshToken}");
redirectView.addStaticAttribute("accessToken", accessToken);
redirectView.addStaticAttribute("refreshToken", refreshToken);

String accessToken = jwtUtil.createAccessToken(member.getLoginId());
String refreshToken = jwtUtil.createRefreshToken(member.getLoginId());
return redirectView;

LoginResponseDto loginResponseDto = new LoginResponseDto(accessToken, refreshToken);
return new BaseResponse<>(BaseResponseStatus.SUCCESS, loginResponseDto);
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.gdsc.hearo.domain.oauth.dto.GoogleOAuthToken;
import com.gdsc.hearo.domain.oauth.dto.GoogleProfile;
import com.gdsc.hearo.domain.oauth.service.social.GoogleOauth;
import com.gdsc.hearo.global.common.BaseException;
import com.gdsc.hearo.global.common.BaseResponseStatus;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -36,7 +34,7 @@ public GoogleProfile requestGoogleProfile(String code) {
return googleOauth.requestGoogleProfile(googleOAuthToken);
}

public Member googleLogin(GoogleProfile googleProfile) throws BaseException {
public Member googleLogin(GoogleProfile googleProfile) {
String email = googleProfile.getEmail();
String googleId = googleProfile.getId();
String username = googleProfile.getName();
Expand Down

0 comments on commit b31e581

Please sign in to comment.