Getting FORBIDDEN (403) error when using authClient.admin

Auth config:
export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: "mysql" }),

  user: {
    additionalFields: {
      document: {
        type: "string",
      },
    },
  },

  plugins: [
    admin({
      adminRoles: [Role.ADMIN],
      defaultRole: Role.AUDITOR,
    }),
    expo(),
  ],

  trustedOrigins: [process.env.APP_URL ?? raise("APP_URL not set"), "locsystem://"],

  emailAndPassword: { enabled: true },
});


Calling this code to change role
authClient.admin.setRole({
  userId: user.id,
  role: data.role,
  fetchOptions: { throw: true },
})


It also happens when creating a new user. The solution for now is call this functions server side but it would be nice if this works well.

I'm logged as an ADMIN and the response is:
image.png
Was this page helpful?