forked from AcaMate/AcaMate_API
[✨] 로그인 관련 데이터 로직 변경
This commit is contained in:
parent
6a543945e7
commit
a9462ca9b5
|
@ -27,7 +27,7 @@ namespace Back.Program.Controllers.V1
|
|||
private readonly IAppRepository _appRepository;
|
||||
private readonly ISessionService _sessionService;
|
||||
|
||||
public AppController(AppDbContext dbContext, ILogger<AppController> logger, IRepositoryService repositoryService, JwtTokenService jwtTokenService,IAppService appService, IAppRepository appRepository, ISessionService sessionService)
|
||||
public AppController(AppDbContext dbContext, ILogger<AppController> logger, IRepositoryService repositoryService, JwtTokenService jwtTokenService, IAppService appService, IAppRepository appRepository, ISessionService sessionService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
|
@ -54,7 +54,7 @@ namespace Back.Program.Controllers.V1
|
|||
}
|
||||
|
||||
[HttpGet("version")]
|
||||
[CustomOperation("앱 버전 확인","앱 버전을 확인해서 업데이트 여부 판단", "시스템")]
|
||||
[CustomOperation("앱 버전 확인", "앱 버전을 확인해서 업데이트 여부 판단", "시스템")]
|
||||
public async Task<IActionResult> GetVersionData(string type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(type)) return BadRequest(APIResponse.InvalidInputError());
|
||||
|
|
|
@ -30,10 +30,16 @@ public class OutController: ControllerBase
|
|||
_kakaoService = kakaoService;
|
||||
_sessionService = sessionService;
|
||||
}
|
||||
|
||||
[HttpGet("kakao/auth")]
|
||||
[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 ?? "");
|
||||
Console.WriteLine($"카카오 로그인 API: {url}");
|
||||
return Ok(new { url });
|
||||
|
@ -46,7 +52,6 @@ public class OutController: ControllerBase
|
|||
Console.WriteLine($"리다이렉트 : {response}");
|
||||
if (success)
|
||||
{
|
||||
// HttpContext.Session.SetString("AccessToken", response);
|
||||
var (idSuccess, idResponse) = await _kakaoService.UserMe(response);
|
||||
if (idSuccess)
|
||||
{
|
||||
|
@ -59,7 +64,6 @@ public class OutController: ControllerBase
|
|||
Console.WriteLine($"login = {loginResult.JsonToString()}");
|
||||
if (loginResult.status.code == "000")
|
||||
{
|
||||
|
||||
var data = loginResult.data as LoginAPIResponse ?? new LoginAPIResponse();
|
||||
if (data != null)
|
||||
{
|
||||
|
@ -68,7 +72,19 @@ public class OutController: ControllerBase
|
|||
if (await _sessionService.SetString("token", token) &&
|
||||
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 Ok(new { id="cc" });
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"ID_res = {idResponse}");
|
||||
|
||||
}
|
||||
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