Patch UI ProviderJWT
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 8m3s

This commit is contained in:
Leandro Hernan Rojas 2025-04-29 08:59:34 -03:00
parent 5e7c71874a
commit 4ae39a9ff2

View File

@ -73,14 +73,26 @@ namespace phronCare.UIBlazor.Services.Authorization
// }; // };
//} //}
public async Task Login(string token) //public async Task Login(string token)
//{
// await js.RemoveItem(TOKENKEY);
// await js.SetInLocalStorage(TOKENKEY, token);
// var authState = BuildAuthenticationState(token);
// NotifyAuthenticationStateChanged(Task.FromResult(authState));
//}
public async Task Login(string tokenJson)
{ {
var tokenData = JsonSerializer.Deserialize<TokenData>(tokenJson);
if (tokenData is null || string.IsNullOrWhiteSpace(tokenData.token))
throw new Exception("Token inválido o mal formado.");
await js.RemoveItem(TOKENKEY); await js.RemoveItem(TOKENKEY);
await js.SetInLocalStorage(TOKENKEY, token); await js.SetInLocalStorage(TOKENKEY, tokenData.token); // ✔️ Guardamos solo el JWT string
var authState = BuildAuthenticationState(token);
var authState = BuildAuthenticationState(tokenData.token);
NotifyAuthenticationStateChanged(Task.FromResult(authState)); NotifyAuthenticationStateChanged(Task.FromResult(authState));
} }
public async Task Logout() public async Task Logout()
{ {
httpClient.DefaultRequestHeaders.Authorization = null; httpClient.DefaultRequestHeaders.Authorization = null;