I want to use jwt tokens auth scheme in my blazor app with global auto interactivity. Content of page is dependant on current auth state and I want to render something else when user is authorized. My problem referes to first render of page on server. How can I determine if user who made request is authorized? I feel like I have to use cookie authorization to store auth token and also send it with refresh page request.
Flow would be following:
- User performs login request through httpClient which sends login and password to server
- Server returns user’s jwt token
- Client app saves it to local sorage and also sets cookie which will be sent to server on page reload
Normally api requests would be authorized through authorization header passed to http client from local storage but when page is refreshed server will recive cookie containing jwt token and based on that authorization will be performed to render according ui.
I know i can use some kind of placeholder for first server render and then adjust ui on client side but i don’t like this solution.
Another solution would be to use only cookie auth and pass state of auth from serwer to interactive components but as far as i know that requires page reload after login request and i want to avoid that.
Taking into account signalR rendering before web assembly is ready porobably could also adds complexity to this solution so i’m wondering if it is good approach or maybe I can use some simpler solution to achieve what i want?