Initialisation
You can use this as a standalone recipe, or alongside any of the other recipes provided by us. To get started, initialise the recipe in the backend SDK's init
function call:
- NodeJS
- GoLang
- Python
import SuperTokens from "supertokens-node";import UserRoles from "supertokens-node/recipe/userroles";
SuperTokens.init({ supertokens: { connectionURI: "..." }, appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ UserRoles.init(), ]});
import ( "github.com/supertokens/supertokens-golang/recipe/userroles" "github.com/supertokens/supertokens-golang/supertokens")
func main() { supertokens.Init(supertokens.TypeInput{ RecipeList: []supertokens.Recipe{ userroles.Init(nil), }, })}
from supertokens_python import InputAppInfo, initfrom supertokens_python.recipe import userroles
init( app_info=InputAppInfo( api_domain="...", app_name="...", website_domain="..." ), framework='...', recipe_list=[ # Initialize other recipes as seen in the quick setup guide userroles.init() ])
By default, the user roles recipe will add the roles and permission information into a user's session (if they have assigned roles & permissions). If you do not want roles or permissions information in the session, or want to manually add it yourself, you can provide the following input configs to the UserRoles.init
function:
- NodeJS
- GoLang
- Python
import UserRoles from "supertokens-node/recipe/userroles";
UserRoles.init({ skipAddingRolesToAccessToken: true, skipAddingPermissionsToAccessToken: true,})
import ( "github.com/supertokens/supertokens-golang/recipe/userroles" "github.com/supertokens/supertokens-golang/recipe/userroles/userrolesmodels" "github.com/supertokens/supertokens-golang/supertokens")
func main() { supertokens.Init(supertokens.TypeInput{ AppInfo: supertokens.AppInfo{ /*...*/ }, RecipeList: []supertokens.Recipe{ userroles.Init(&userrolesmodels.TypeInput{ SkipAddingRolesToAccessToken: true, SkipAddingPermissionsToAccessToken: true, }), }, })}
from supertokens_python import InputAppInfo, initfrom supertokens_python.recipe import userroles
init( app_info=InputAppInfo( api_domain="...", app_name="...", website_domain="..." ), framework='...', recipe_list=[ userroles.init(skip_adding_roles_to_access_token=True, skip_adding_permissions_to_access_token=True) ])