diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js index a500b84da7d1f5c76ae873b0f24161d95ab23a4d..d937610e79caf5325e82a4f3afa3699de5daa31d 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js @@ -129,12 +129,19 @@ async function postRegister (params = {}) { const { autoSetInviteCode, // 注册时自动设置邀请码 - forceInviteCode // 必须有邀请码才允许注册,注意此逻辑不可对admin生效 + forceInviteCode, // 必须有邀请码才允许注册,注意此逻辑不可对admin生效 + userRegisterDefaultRole // 用户注册时配置的默认角色 } = this.config if (autoSetInviteCode) { user.my_invite_code = await getValidInviteCode() } + // 如果用户注册默认角色配置存在且不为空数组 + if (userRegisterDefaultRole && userRegisterDefaultRole.length) { + // 将用户已有的角色和配置的默认角色合并成一个数组,并去重 + user.role = Array.from(new Set([...(user.role || []), ...userRegisterDefaultRole])) + } + const isAdmin = user.role && user.role.includes('admin') if (forceInviteCode && !isAdmin && !inviteCode) {