Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement route guards in Blazor?

I am currently trying out Blazor and has successfully created a JWT Auth login. Im in the part where im trying to create guards but the doc provided by Microsoft doesnt really explain much. Is there any way someone could guide me in the right direction for securing my routes if the user is not logged in? thank you.

like image 433
Mark Conrad Ibiaz Avatar asked Oct 20 '25 16:10

Mark Conrad Ibiaz


1 Answers

The concept of route guards in Blazor does not currently exist. The route system in Blazor is rather poor, but I guess this is going to change in the near future.

As a temporary solution I suggest you store the JWT token in the local storage, and read it for validation whenever the user attempts to access secured parts of your application. You may create a service that you can call to check for access permission during the Init or OnParametersSet component's life-cycle methods.

Of course you can implement your own custom router ;)

Hope this helps...

like image 167
enet Avatar answered Oct 22 '25 12:10

enet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!