forked from AcaMate/AcaMate_Web
[✨] 카카오 로그인 버튼 구현
This commit is contained in:
parent
e207e246cd
commit
a76e5fd574
|
@ -1,3 +1,5 @@
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
using System.Text.Json;
|
||||||
using Front.Program.Services;
|
using Front.Program.Services;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
|
@ -7,23 +9,21 @@ namespace Front.Program.Views.Project;
|
||||||
public partial class Auth : ComponentBase
|
public partial class Auth : ComponentBase
|
||||||
{
|
{
|
||||||
[Inject] NavigationManager NavigationManager { get; set; } = default!;
|
[Inject] NavigationManager NavigationManager { get; set; } = default!;
|
||||||
[Inject] IJSRuntime JS { get; set; } = default!;
|
// [Inject] IJSRuntime JS { get; set; } = default!;
|
||||||
[Inject] CookieService Cookie {get; set;} = default!;
|
// [Inject] CookieService Cookie { get; set; } = default!;
|
||||||
|
[Inject] HttpClient Http { get; set; } = default!;
|
||||||
|
|
||||||
public async Task KakaoLogin()
|
public async Task KakaoLogin()
|
||||||
{
|
{
|
||||||
var headerKey = "Web_AM_Connect_Key";
|
var url = "/api/v1/out/user/kakao/auth";
|
||||||
// var headerValue = await JS.InvokeAsync<string>("eval", "document.cookie.match(/Web_AM_Connect_Key=([^;]+)/)?.[1] || ''");
|
var response = await Http.GetFromJsonAsync<JsonElement>(url);
|
||||||
|
var kakaoUrl = response.GetProperty("url").GetString();
|
||||||
|
|
||||||
// NavigationManager.NavigateTo("/api/v1/in/user/kakao/auth", true);
|
Console.WriteLine(kakaoUrl);
|
||||||
Cookie.GetCookieAsync(headerKey).ContinueWith(async task =>
|
|
||||||
{
|
|
||||||
var cookie = task.Result;
|
|
||||||
if (!string.IsNullOrEmpty(cookie))
|
|
||||||
{
|
|
||||||
await JS.InvokeVoidAsync("postWithHeader", "/api/v1/in/user/kakao/auth", "GET", headerKey, cookie);
|
|
||||||
|
|
||||||
}
|
if (!string.IsNullOrEmpty(kakaoUrl))
|
||||||
});
|
{
|
||||||
|
NavigationManager.NavigateTo(kakaoUrl, true); // 카카오 인증 페이지로 이동
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user