How is Authorised Routes and Content Handled
See original GitHub issueWhat is the equivalent way to do the following in Bolero?
Authorized Views
<AuthorizeView>
<Authorized>
<h1>Hello, @context.User.Identity.Name!</h1>
<p>You can only see this content if you're authenticated.</p>
</Authorized>
<Authorizing>
<h1>Authentication in progress</h1>
<p>You can only see this content while authentication is in progress.</p>
</Authorizing>
<NotAuthorized>
<h1>Authentication Failure!</h1>
<p>You're not signed in.</p>
</NotAuthorized>
<AuthorizeView Roles="admin, superuser">
<p>You can only see this if you're an admin or superuser.</p>
</AuthorizeView>
</AuthorizeView>
Authorized Attribute
@page "/"
@attribute [Authorize(Roles = "admin, superuser")]
<p>You can only see this if you're in the 'admin' or 'superuser' role.</p>
Authorized Routes
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<h1>Sorry</h1>
<p>You're not authorized to reach this page.</p>
<p>You may need to log in as a different user.</p>
</NotAuthorized>
<Authorizing>
<h1>Authentication in progress</h1>
<p>Only visible while authentication is in progress.</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<h1>Sorry</h1>
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
React Router 6: Private Routes (alias Protected Routes)
Private Routes in React Router (also called Protected Routes) require a user being authorized to visit a route (read: page). ... content of...
Read more >How To Handle Routing in React Apps with React Router
This means that you can declare exactly which of your components has a certain route. With declarative routing, you can create intuitive routes ......
Read more >Implementing Protected Route and Authentication in React ...
Protected Routes are routes that can only be accessed if a condition is met(usually, if user is properly authenticated). It returns a Route ......
Read more >Complete guide to authentication with React Router v6
It provides a declarative, component-based approach to routing and handles ... routes so that unauthenticated users cannot access certain content ...
Read more >How is Authorised Routes and Content Handled
What is the equivalent way to do the following in Bolero? # Authorized Views ``` Hello, @context.User.Identity.Name! You can only see...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve started to look into how to best handle authorization, but I don’t really have full guidelines to do this yet. That being said, it should be possible to call
AuthorizeView
directly usingcomp
, something like this (untested):I think using
[<Authorize(Roles = "admin, superuser")>]
on a component class (for example on a class inheriting fromElmishComponent
) should be equivalent to the second case, although I don’t quite know how and when it’s checked.Just wanted to share my opinion on the matter. In functional programming, we generally avoid these kind of magical components, because of power of composition, usually it’s not hard to come up with your home grown solution that achieves the same.