mirror of
https://github.com/Shchoholiev/shopping-assistant-web-client.git
synced 2025-04-10 00:48:50 +00:00
Merge pull request #7 from Shchoholiev/bug/SA-142-fix-login-page-loop
SA-142 login loop fixed
This commit is contained in:
commit
7224f7c60e
ShoppingAssistantWebClient.Web
@ -15,7 +15,7 @@ public static class DependencyInjectionExtension
|
||||
client.BaseAddress = new Uri(apiUrl + "api/");
|
||||
});
|
||||
|
||||
services.AddScoped<GraphQLHttpClient>(p =>
|
||||
services.AddSingleton<GraphQLHttpClient>(p =>
|
||||
new GraphQLHttpClient(apiUrl + "graphql", new NewtonsoftJsonSerializer())
|
||||
);
|
||||
|
||||
|
@ -15,22 +15,25 @@ public class GlobalUserMiddleware
|
||||
|
||||
public async Task InvokeAsync(HttpContext httpContext, AuthenticationService authenticationService, ApiClient apiClient)
|
||||
{
|
||||
try
|
||||
if (httpContext.Request.Path != "/login")
|
||||
{
|
||||
var accessToken = await authenticationService.GetAuthTokenAsync();
|
||||
if (!string.IsNullOrEmpty(accessToken))
|
||||
try
|
||||
{
|
||||
apiClient.JwtToken = accessToken;
|
||||
GlobalUser.Roles = authenticationService.GetRolesFromJwtToken(accessToken);
|
||||
GlobalUser.Id = authenticationService.GetIdFromJwtToken(accessToken);
|
||||
GlobalUser.Email = authenticationService.GetEmailFromJwtToken(accessToken);
|
||||
GlobalUser.Phone = authenticationService.GetPhoneFromJwtToken(accessToken);
|
||||
var accessToken = await authenticationService.GetAuthTokenAsync();
|
||||
if (!string.IsNullOrEmpty(accessToken))
|
||||
{
|
||||
apiClient.JwtToken = accessToken;
|
||||
GlobalUser.Roles = authenticationService.GetRolesFromJwtToken(accessToken);
|
||||
GlobalUser.Id = authenticationService.GetIdFromJwtToken(accessToken);
|
||||
GlobalUser.Email = authenticationService.GetEmailFromJwtToken(accessToken);
|
||||
GlobalUser.Phone = authenticationService.GetPhoneFromJwtToken(accessToken);
|
||||
}
|
||||
}
|
||||
catch (AuthenticationException ex)
|
||||
{
|
||||
httpContext.Response.Cookies.Delete("accessToken");
|
||||
httpContext.Response.Redirect("/login");
|
||||
}
|
||||
}
|
||||
catch (AuthenticationException ex)
|
||||
{
|
||||
httpContext.Response.Cookies.Delete("accessToken");
|
||||
httpContext.Response.Redirect("/login");
|
||||
}
|
||||
await _next(httpContext);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user