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.
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The context of the request. |
userKey | string | Yes | The key of the user who holds the role. |
roleKey | string | Yes | The key of the role to remove from the user. |
tenantKey | string | Yes | The 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:
ErrorCode | Cause |
|---|---|
NotFound | HTTP 404: the user doesn't hold that role in that tenant. |
UnprocessableEntityError | HTTP 422: an argument failed validation. |
Unauthorized, ForbiddenAccess | HTTP 401 or 403: the API key is invalid or has no access to the environment. |
UnexpectedError | A server error (HTTP 5xx) or a network error. |