Masonite Inertia
4.X
4.X
  • Introduction
  • Installation
  • Demo app
  • The basics
    • Routing
    • Responses
    • Redirects
    • Validation
    • Shared data
    • File uploads
  • Advanced
    • Configuration
    • Root view
    • Partial reloads
    • Authorization
    • CSRF protection
    • Error handling
    • Assets versioning
    • Server-side rendering
    • Testing
  • Development
    • Changelog
    • Contribute
    • Support
Powered by GitBook
On this page

Was this helpful?

  1. Advanced

Authorization

With Inertia, authorization is best handled server-side in your policies. However, you may be wondering how to check against your policies from within your JavaScript page components, since you won't have access to your server-side helpers. The simplest approach here is to pass your authorization checks as props to your page components.

app/http/controllers/UsersController.py
from masonite.auth import Auth
from masonite.inertia import InertiaResponse

class UsersController(Controller):

    def index(self, auth: Auth, view:InertiaResponse):
        return view.render("Users/Index", {
            "can": {
                "create_user": # add custom check with the current user auth.user()
            },
            "users": User.all().serialize()
        })
PreviousPartial reloadsNextCSRF protection

Last updated 3 years ago

Was this helpful?