forked from AcaMate/AcaMate_API
[✨] 로그인 관련 데이터 로직 변경
This commit is contained in:
parent
6a543945e7
commit
a9462ca9b5
|
@ -30,10 +30,16 @@ public class OutController: ControllerBase
|
||||||
_kakaoService = kakaoService;
|
_kakaoService = kakaoService;
|
||||||
_sessionService = sessionService;
|
_sessionService = sessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("kakao/auth")]
|
[HttpGet("kakao/auth")]
|
||||||
[CustomOperation("카카오 로그인", "카카오 로그인 동작", "사용자")]
|
[CustomOperation("카카오 로그인", "카카오 로그인 동작", "사용자")]
|
||||||
public async Task<IActionResult> KakaoLogin([FromQuery] string? scope)
|
public async Task<IActionResult> KakaoLogin([FromQuery] string? scope, [FromQuery] string? redirectPath)
|
||||||
{
|
{
|
||||||
|
if (!string.IsNullOrEmpty(redirectPath))
|
||||||
|
{
|
||||||
|
await _sessionService.SetString("redirectPath", redirectPath);
|
||||||
|
}
|
||||||
|
|
||||||
var url = await _kakaoService.GetAuthorizationUrl(scope ?? "");
|
var url = await _kakaoService.GetAuthorizationUrl(scope ?? "");
|
||||||
Console.WriteLine($"카카오 로그인 API: {url}");
|
Console.WriteLine($"카카오 로그인 API: {url}");
|
||||||
return Ok(new { url });
|
return Ok(new { url });
|
||||||
|
@ -46,7 +52,6 @@ public class OutController: ControllerBase
|
||||||
Console.WriteLine($"리다이렉트 : {response}");
|
Console.WriteLine($"리다이렉트 : {response}");
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
// HttpContext.Session.SetString("AccessToken", response);
|
|
||||||
var (idSuccess, idResponse) = await _kakaoService.UserMe(response);
|
var (idSuccess, idResponse) = await _kakaoService.UserMe(response);
|
||||||
if (idSuccess)
|
if (idSuccess)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +64,6 @@ public class OutController: ControllerBase
|
||||||
Console.WriteLine($"login = {loginResult.JsonToString()}");
|
Console.WriteLine($"login = {loginResult.JsonToString()}");
|
||||||
if (loginResult.status.code == "000")
|
if (loginResult.status.code == "000")
|
||||||
{
|
{
|
||||||
|
|
||||||
var data = loginResult.data as LoginAPIResponse ?? new LoginAPIResponse();
|
var data = loginResult.data as LoginAPIResponse ?? new LoginAPIResponse();
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +72,19 @@ public class OutController: ControllerBase
|
||||||
if (await _sessionService.SetString("token", token) &&
|
if (await _sessionService.SetString("token", token) &&
|
||||||
await _sessionService.SetString("refresh", refresh))
|
await _sessionService.SetString("refresh", refresh))
|
||||||
{
|
{
|
||||||
return Redirect("/about");
|
var (hasPath, redirectPath) = await _sessionService.GetString("redirectPath");
|
||||||
|
await _sessionService.Remove("redirectPath"); // 사용 후 세션에서 제거
|
||||||
|
|
||||||
|
// 로그인 성공 flag 쿠키 저장
|
||||||
|
Response.Cookies.Append("IsLogin", "true", new CookieOptions
|
||||||
|
{
|
||||||
|
HttpOnly = false,
|
||||||
|
Secure = true,
|
||||||
|
SameSite = SameSiteMode.Lax,
|
||||||
|
Path = "/",
|
||||||
|
Expires = DateTime.Now.AddDays(1)
|
||||||
|
});
|
||||||
|
return Redirect(hasPath && !string.IsNullOrEmpty(redirectPath) ? redirectPath : "/about");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,13 +99,20 @@ public class OutController: ControllerBase
|
||||||
{
|
{
|
||||||
return BadRequest(new { error = "로그인 실패", message = loginResult.status.message });
|
return BadRequest(new { error = "로그인 실패", message = loginResult.status.message });
|
||||||
}
|
}
|
||||||
// return Ok(new { id="cc" });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine($"ID_res = {idResponse}");
|
Console.WriteLine($"ID_res = {idResponse}");
|
||||||
|
|
||||||
}
|
}
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// // 로그아웃 API 예시 (이미 있다면 해당 위치에 추가)
|
||||||
|
// [HttpGet("logout")]
|
||||||
|
// public IActionResult Logout()
|
||||||
|
// {
|
||||||
|
// // 세션/쿠키 등 로그아웃 처리
|
||||||
|
// Response.Cookies.Delete("IsLogin");
|
||||||
|
// // 기타 로그아웃 처리 로직...
|
||||||
|
// return Redirect("/");
|
||||||
|
// }
|
||||||
}
|
}
|
1669
package-lock.json
generated
Normal file
1669
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user