You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example: Can the current user read a resource of type "myResource" with id "1"?
import{authenticate}from"@/authentication/authenticateAndAuthorize";constauthentication=awaitauthenticate();if(!authentication.authorize("myResource","read",[{key: "id",value: "1"}]))thrownewError("Forbidden");// Do something
Example: Authenticate and authorize a server action
import{authenticateAction}from"@/authentication/authenticateAndAuthorize";exportconstcreateMyResourceAction=async()=>{constauthentication=awaitauthenticateAction("createMyResourceAction");authentication.authorizeAction("myResource","create");// Do something};
Example: Authenticate and authorize a page view
import{authenticatePage}from"@/authentication/authenticateAndAuthorize";exportdefaultasyncfunctionPage({ params }){const{ id }=awaitparams;constauthentication=awaitauthenticatePage("/admin/myResource/[id]");authentication.authorizePage("myResource","create",[{key: "id",value: id},]);// Render the page}