How to add role to user with authLib?

Enonic version: 7.12.1
OS: Linux

Can you please tell me how to add roles to user with authLib.
I didn’t find it in the doc - Authentication Library - Enonic Developer Portal

Have you tried addMembers() ?


var authLib = require('/lib/xp/auth.js');
authLib.addMembers('role:myRole', ['user:myUsers:myUserName']);
1 Like

Thanks a lot, that works perfect!

I was a bit confusing about authLib.addMembers function (what is principal and what is members and there were no example in the doc), but now it’s clear.