Mark Conrad Ibiaz
Mark Conrad Ibiaz

Reputation: 41

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.

Upvotes: 4

Views: 2476

Answers (1)

enet
enet

Reputation: 45764

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...

Upvotes: 5

Related Questions