Skip to content

Commit

Permalink
Merge pull request #30 from 9oormthon-univ/dev
Browse files Browse the repository at this point in the history
[#2]🐛Fix: 로그인 유무
  • Loading branch information
sumin220 authored Nov 22, 2024
2 parents b548f34 + 5e05194 commit 287c41f
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package univ.yesummit.global.auth.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;


import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/v1/api/kakao")
public class AuthController {
Expand All @@ -15,4 +22,18 @@ public class AuthController {
public RedirectView login() {
return new RedirectView("/oauth2/authorization/kakao");
}
}

@GetMapping("/status")
@Operation(summary = "로그인 상태 확인", description = "사용자의 로그인 상태를 확인합니다.")
public ResponseEntity<Map<String, Boolean>> getLoginStatus(HttpServletRequest request) {
// 쿠키 또는 세션에서 로그인 상태를 확인
HttpSession session = request.getSession(false); // 세션이 없으면 null 반환
boolean loggedIn = session != null && session.getAttribute("user") != null;

// 응답 데이터 생성
Map<String, Boolean> response = new HashMap<>();
response.put("loggedIn", loggedIn);

return ResponseEntity.ok(response);
}
}

0 comments on commit 287c41f

Please sign in to comment.