Hi, hope your doing well. I'm newbie to react and ...
# support-questions-legacy
g
Hi, hope your doing well. I'm newbie to react and node. i have used prebuilt UI and want to user roles recipe, i have gone through the documentation - https://supertokens.com/docs/userroles/creating-role but couldn't figure out how to add roles to a user. or check if any roles were added, i have tried but couldn't make it working. any help or suggestions?
r
hey @gsj where are you adding a role to the user?
g
In backend -> config.ts
r
what is the result of calling
addRoleToUser
?
g
Error creating roles: Error: Initialisation not done. Did you forget to call the UserRoles.init or SuperTokens.init functions? at Function.getInstanceOrThrowError (C:\Users\gouta\super-tokens\supertoken_demo\backend\node_modules\supertokens-node\lib\build\recipe\userroles\recipe.js:61:15) at Function.getAllRoles (C:\Users\gouta\super-tokens\supertoken_demo\backend\node_modules\supertokens-node\lib\build\recipe\userroles\index.js:90:39) at C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:246:47 at step (C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:44:23) at Object.next (C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:25:53) at C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:19:71 at new Promise () at __awaiter (C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:15:12) at getAllRoles (C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:358:12) at Object. (C:\Users\gouta\super-tokens\supertoken_demo\backend\config.ts:257:1)
this is the error on terminal.
i'm calling addRoleToUser here.
r
you need to do userroles.init on the backend recipeList
g
Yes, i have added that in recipeList Session.init(), Dashboard.init(), UserRoles.init()
r
make sure you don't have multiple supertokens.init config on the backend
if that error comes again, it must meant something is wrong on your end, so please double check
g
in index.ts supertokens.init(SuperTokensConfig); only part where this is initialised in backend App.tsx supertokens.init(SuperTokensConfig); only part where this is initialised in frontend.
4 Views