- Gate various UI and actions in your application’s frontend
- Confirm authentication and authorization on your backend before honoring requests from the client
Frontend authorization checks
Use Stytch’s frontend SDKs to check user permissions client-side.Conditionally render UI based on permissions
It’s good practice to adapt UI based on permissions, even if your backend will enforce permissions on the server-side.Check permissions before making API requests
You should also do pre-emptive client-side authorization checks to avoid any unnecessary API requests or ensure the user isn’t about to enter a flow they cannot complete.Built-in Stytch Resource authorization
Stytch’s frontend SDKs offer built-in RBAC protections, allowing you to make requests directly from your public client without proxying through your backend. When you call methods likeorganization.update() or magicLinks.email.invite() directly from the client:
- The frontend SDK will automatically include the logged in member’s session in the request to the Stytch API.
- The Stytch API will only authorize the request if the session is valid and the Member has at least one Role that grants them permission to take that action.
Backend authorization checks
Regardless of if you are using Stytch’s frontend SDKs, you must always perform server-side authorization checks before proceeding with a request by authorizing a valid Session Token or .- Session Tokens
- JWTs
If you are using Session Tokens, session authentication will trigger an outbound call to Stytch and authorization will be done on Stytch’s servers.For example to check authorization in a python backend:
Built-in Stytch Resource authorization
Any Stytch API endpoints and Backend SDK methods that act on a default Stytch Resource (e.g.stytch.self or stytch.organization) support passing the Member’s Session Token or Session JWT to have Stytch perform authentication and authorization prior to honoring the request.
This allows the authentication and authorization checks to occur as close as possible to the action being taken, streamlining your handling.
For example, if a Member makes a request to delete another Member from an Organization, you can pass their Session Token or JWT into the organizations.members.delete() call. Stytch will authenticate the session and perform an authorization check prior to honoring the call.