diff --git a/phronCare.UIBlazor/Services/Authorization/CustomAuthorizationProvider.cs b/phronCare.UIBlazor/Services/Authorization/CustomAuthorizationProvider.cs index 115d95b..4becc9f 100644 --- a/phronCare.UIBlazor/Services/Authorization/CustomAuthorizationProvider.cs +++ b/phronCare.UIBlazor/Services/Authorization/CustomAuthorizationProvider.cs @@ -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(tokenJson); + + if (tokenData is null || string.IsNullOrWhiteSpace(tokenData.token)) + throw new Exception("Token inválido o mal formado."); + await js.RemoveItem(TOKENKEY); - await js.SetInLocalStorage(TOKENKEY, token); - var authState = BuildAuthenticationState(token); + await js.SetInLocalStorage(TOKENKEY, tokenData.token); // ✔️ Guardamos solo el JWT string + + var authState = BuildAuthenticationState(tokenData.token); NotifyAuthenticationStateChanged(Task.FromResult(authState)); } - public async Task Logout() { httpClient.DefaultRequestHeaders.Authorization = null;