C
C#11mo ago
Brutal_Boost

I have some questions about detecting the currently logged in user and how to handle it.

I am working on my first .NET CORE blazor website. I've always just done back end stuff and am working on a full-stack app now. I have a couple of questions. 1. What's the correct way to keep track of the current logged in user? I was thinking I would create a current user class that would hold the current users ID and with that ID I can grab anything I need for that user. 2. More of a design question, but what's the proper way of handling whether a user is logged in or not. Off the top of my head I can think of 3 different ways of handling a user being logged in or not. 1. The user has to login upon accessing the website and can't do anything until logged in (Facebook/Instagram) 2. The user has access to basic information, such as an about page, maybe a pricing page, etc. Then once logged in they have access to more options such as their account settings and the purpose of the website itself, but also still has access to the pages that users who aren't logged into has access to. 3. Similar to the one above, the user has access to specific about pages, pricing, etc. But upon logging in it brings them to an entirely different place where they access the main portion of the website but can't access the same pages a user who isn't logged in can access. Sorry this is a lot! I didn't know how to structure these for google searches so I wasn't getting any good info.
3 Replies
Joschi
Joschi11mo ago
Is this a standalone WASM app with a backend API? I guess you wanna know if the user is logged in in the frontend?
Joschi
Joschi11mo ago
In general for handling authorization in Blazor (control what each user can see based on their authentication status and roles) you can use the AuthorizeView component This article talks about that and some points to keep in mind when securing your app https://learn.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-8.0
ASP.NET Core Blazor authentication and authorization
Learn about Blazor authentication and authorization scenarios.
Brutal_Boost
Brutal_BoostOP11mo ago
Awesome I will look into that. And correct it's WASM with a backend API
Want results from more Discord servers?
Add your server