forked from AcaMate/AcaMate_Web
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
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; }
|
|
}
|
|
} |