Blazor: Redirect to Login page when there is no session / JWT token?

前端 未结 4 1048
失恋的感觉
失恋的感觉 2021-01-28 09:14

I am trying to create a new application in Blazor and am working on authentication. I am using a JWT tokens that is stored in Local storage. When the application loads i need to

4条回答
  •  别那么骄傲
    2021-01-28 09:37

    A solution (for now, not the best i think?) is to create a base class for all component pages to inherit from and override the OnInit method to do the checks and redirects. This also works when navigating to a link after the application has loaded.

    A check in the app.cshtml component only works for the initial startup, not when navigating within the application. This would be nice for other checks, but not to protect routes.

提交回复
热议问题