This commit is contained in:
6d486f49
2026-08-17 01:13:48 -04:00
parent 1d6207fbfe
commit ffaab59585
26 changed files with 3133 additions and 105 deletions
+49 -5
View File
@@ -16,9 +16,9 @@ public class AuthService
_http = http;
_networkStatus = networkStatus;
_jsRuntime = serviceProvider.GetService(typeof(IJSRuntime)) as IJSRuntime;
_graphqlEndpoint = http.BaseAddress != null && http.BaseAddress.Port == 5256
_graphqlEndpoint = http.BaseAddress != null && http.BaseAddress.Port == 7266
? "/graphql"
: "http://localhost:5256/graphql";
: "https://localhost:7266/graphql";
}
public bool IsLoggedIn => !string.IsNullOrEmpty(AuthToken);
@@ -34,6 +34,32 @@ public class AuthService
{
var storedToken = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", "chrono_auth_token");
var storedUser = await _jsRuntime.InvokeAsync<string?>("localStorage.getItem", "chrono_auth_user");
if (string.IsNullOrEmpty(storedToken) || string.IsNullOrEmpty(storedUser))
{
try
{
var cookieStr = await _jsRuntime.InvokeAsync<string?>("eval", "document.cookie");
if (!string.IsNullOrEmpty(cookieStr))
{
foreach (var part in cookieStr.Split(';'))
{
var kv = part.Trim().Split('=');
if (kv.Length == 2)
{
if (kv[0] == "chrono_auth_token" && string.IsNullOrEmpty(storedToken))
storedToken = kv[1];
if (kv[0] == "chrono_auth_user" && string.IsNullOrEmpty(storedUser))
storedUser = kv[1];
}
}
}
}
catch
{
}
}
if (!string.IsNullOrEmpty(storedToken) && !string.IsNullOrEmpty(storedUser))
{
AuthToken = storedToken;
@@ -133,9 +159,12 @@ public class AuthService
if (httpResponse.IsSuccessStatusCode)
return await httpResponse.Content.ReadFromJsonAsync<GraphQLResponse<T>>();
if (_graphqlEndpoint == "/graphql")
if (_graphqlEndpoint == "/graphql" || _graphqlEndpoint.StartsWith("https://"))
{
var fallbackResponse = await _http.PostAsJsonAsync("http://localhost:5256/graphql", request);
var fallbackUrl = _graphqlEndpoint == "/graphql"
? "https://localhost:7266/graphql"
: "http://localhost:7266/graphql";
var fallbackResponse = await _http.PostAsJsonAsync(fallbackUrl, request);
if (fallbackResponse.IsSuccessStatusCode)
return await fallbackResponse.Content.ReadFromJsonAsync<GraphQLResponse<T>>();
}
@@ -144,12 +173,27 @@ public class AuthService
{
try
{
var fallbackResponse = await _http.PostAsJsonAsync("http://localhost:5256/graphql", request);
var fallbackUrl = _graphqlEndpoint.StartsWith("http://")
? "https://localhost:7266/graphql"
: "http://localhost:7266/graphql";
var fallbackResponse = await _http.PostAsJsonAsync(fallbackUrl, request);
if (fallbackResponse.IsSuccessStatusCode)
return await fallbackResponse.Content.ReadFromJsonAsync<GraphQLResponse<T>>();
}
catch
{
if (_graphqlEndpoint == "/graphql")
{
try
{
var fallbackHttp = await _http.PostAsJsonAsync("http://localhost:7266/graphql", request);
if (fallbackHttp.IsSuccessStatusCode)
return await fallbackHttp.Content.ReadFromJsonAsync<GraphQLResponse<T>>();
}
catch
{
}
}
}
}