Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/BlazorShop.Web/Client/App.razor
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<Login />
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<CascadingAuthenticationState>
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<Login />
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>

<LayoutView Layout="@typeof(MainLayout)">
<NotFound404 />
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
</NotFound>
</Router>
</CascadingAuthenticationState>
12 changes: 11 additions & 1 deletion src/BlazorShop.Web/Client/Pages/Products/ProductsList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ else
}

@code {
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }

private readonly ProductsSearchRequestModel model = new ProductsSearchRequestModel();

private ProductsSearchResponseModel searchResponse;
Expand Down Expand Up @@ -350,6 +353,13 @@ else

private async Task AddToCart(int id)
{
var user = (await authenticationStateTask).User;
if (!user.Identity.IsAuthenticated)
{
this.NavigationManager.NavigateTo("/account/login");
return;
}

var cartRequest = new ShoppingCartRequestModel
{
ProductId = id,
Expand Down Expand Up @@ -401,4 +411,4 @@ else
this.NavigationManager.NavigateTo($"/products/page/{this.model.Page}");
}
}
}
}