forked from AcaMate/AcaMate_Web
[✨] 동작 로직 수정
1. 퍼블리시 동작 로직 수정 2. 쿠키 설정 동작 로직 추가
This commit is contained in:
parent
1f3b6b3217
commit
9167e2a9d6
37
App.razor.cs
Normal file
37
App.razor.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Front;
|
||||
|
||||
public partial class App : ComponentBase
|
||||
{
|
||||
[Inject] HttpClient Http { get; set; } = default!;
|
||||
[Inject] IJSRuntime JS { get; set; } = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
// Web_AM_Connect_Key 쿠키를 가져오는 JavaScript 함수를 호출합니다.
|
||||
var header = await JS.InvokeAsync<string>("blazorGetCookie", "Web_AM_Connect_Key");
|
||||
|
||||
// 값 없으면 API 호출
|
||||
if (string.IsNullOrEmpty(header))
|
||||
{
|
||||
var response = await Http.GetFromJsonAsync<ApiResult>("/api/v1/in/app?type=W&specific=Web_Connect&project=AcaMate");
|
||||
Console.WriteLine($"COOKIE: {response.header}");
|
||||
if (!string.IsNullOrEmpty(response?.header))
|
||||
{
|
||||
Console.WriteLine($"NO?");
|
||||
await JS.InvokeVoidAsync("blazorSetCookie", "Web_AM_Connect_Key", response.header, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class ApiResult
|
||||
{
|
||||
public string header { get; set; }
|
||||
}
|
||||
}
|
10
Program.cs
10
Program.cs
|
@ -10,12 +10,16 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|||
builder.RootComponents.Add<App>("#app");
|
||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
||||
|
||||
// builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||||
|
||||
builder.Services.AddScoped(sp => //new HttpClient
|
||||
{
|
||||
// BaseAddress = new Uri("https://localhost:5144")
|
||||
|
||||
// BaseAddress = new Uri("https://localhost:5144");
|
||||
var config = builder.Configuration;
|
||||
var http = new HttpClient();
|
||||
var http = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
||||
};
|
||||
return http;
|
||||
});
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
<div class="w-full max-w-xs">
|
||||
<input type="text" placeholder="아이디" class="mb-4 p-2 border border-gray-300 rounded w-full" />
|
||||
<input type="password" placeholder="비밀번호" class="mb-4 p-2 border border-gray-300 rounded w-full" />
|
||||
<button class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 w-full">로그인</button>
|
||||
<button @onclick = "KakaoLogin" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700 w-full">로그인</button>
|
||||
</div>
|
||||
</div>
|
|
@ -4,5 +4,10 @@ namespace Front.Program.Views.Project;
|
|||
|
||||
public partial class Auth : ComponentBase
|
||||
{
|
||||
|
||||
[Inject] NavigationManager NavigationManager { get; set; } = default!;
|
||||
void KakaoLogin()
|
||||
{
|
||||
// Redirect to Kakao login page
|
||||
NavigationManager.NavigateTo("/api/v1/in/user/kakao/auth", true);
|
||||
}
|
||||
}
|
|
@ -49,5 +49,23 @@
|
|||
console.error("❌ Blazor 로딩 실패", err);
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
window.blazorGetCookie = function (name) {
|
||||
alert("blazorGetCookie 호출됨");
|
||||
const v = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)');
|
||||
return v ? v.pop() : '';
|
||||
};
|
||||
window.blazorSetCookie = function (name, value, days) {
|
||||
alert("blazorSetCookie 호출됨");
|
||||
let expires = "";
|
||||
if (days) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (days*24*60*60*1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
||||
console.log("쿠키 생성됨:", document.cookie);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user