question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How is Authorised Routes and Content Handled

See original GitHub issue

What 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:open
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Tarmilcommented, Apr 6, 2020

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 using comp, something like this (untested):

comp<AuthorizeView> [] [
    comp<Authorized> [] [
        h1 [] [textf "Hello, %s!" context.User.Identity.Name]
        p [] [text "You can only see this content if you're authenticated."]
    ]
    comp<Authorizing> [] [
        h1 [] [text "Authentication in progress"]
        p [] [text "You can only see this content while authentication is in progress."]
    ]
    comp<NotAuthorized> [] [
        h1 [] [text "Authentication failure!"]
        p [] [text "You're not signed in."]
    ]
    comp<AuthorizeView> ["Roles" => "admin, superuser"] [
        p [] [text "You can only see this if you're an admin or superuser."]
    ]
]

I think using [<Authorize(Roles = "admin, superuser")>] on a component class (for example on a class inheriting from ElmishComponent) should be equivalent to the second case, although I don’t quite know how and when it’s checked.

1reaction
OnurGumuscommented, Apr 6, 2020

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found