Skip to main content

Unassign a role from a user with the Go SDK

Permit.Api.Users.UnassignRole() removes a role that a user holds within one tenant. Role assignments of the same role in other tenants stay in place. This reference is for Go developers who revoke permissions from backend code.

Users.UnassignRole signature

func (u *Users) UnassignRole(ctx context.Context, userKey string, roleKey string, tenantKey string) (*models.UserRead, error)

Users.UnassignRole parameters

Users.UnassignRole takes positional arguments, not a struct.

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
userKeystringYesThe key of the user who holds the role.
roleKeystringYesThe key of the role to remove from the user.
tenantKeystringYesThe key of the tenant in which the user holds the role.

Example: unassign a role with Users.UnassignRole

The example uses a client named Permit, created with permit.NewPermit() as shown in Check permissions with the Go SDK, and a ctx of type context.Context. Replace user-key, role-key, and tenant-key with your own keys:

user, err := Permit.Api.Users.UnassignRole(ctx, "user-key", "role-key", "tenant-key")

Users.UnassignRole return value and errors

On success, Users.UnassignRole returns a *models.UserRead for the user.

If the call fails, err holds an errors.PermitError from the github.com/permitio/permit-golang/pkg/errors package. Its StatusCode field has the HTTP status, and its ErrorCode field has one of these codes:

ErrorCodeCause
NotFoundHTTP 404: the user doesn't hold that role in that tenant.
UnprocessableEntityErrorHTTP 422: an argument failed validation.
Unauthorized, ForbiddenAccessHTTP 401 or 403: the API key is invalid or has no access to the environment.
UnexpectedErrorA server error (HTTP 5xx) or a network error.