> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-1-authentication-authorization/authorization/role.md).

# Role

Defines a user's permissions.

We'll store the possible roles for a user in an <mark style="color:blue;">enum</mark>. So first, create the file <mark style="color:purple;">auth</mark>/<mark style="color:purple;">roles</mark>/<mark style="color:purple;">enums</mark>/<mark style="color:purple;">role.enum</mark> with following content.

```typescript
export enum Role {
  ADMIN = 'ADMIN',
  MANAGER = 'MANAGER',
  USER = 'USER',
}
```

Now, let's go back to the <mark style="color:blue;">`User`</mark> entity and declare a <mark style="color:blue;">`role`</mark> for it. This is how we can map an <mark style="color:blue;">enum</mark> to the database. Also notice the <mark style="color:blue;">`default`</mark> value.

```typescript
@Column({
  type: 'enum',
  enum: Role,
  enumName: 'role_enum',
  default: Role.USER,
})
role: Role;
```

{% hint style="info" %}
The <mark style="color:blue;">`enumName`</mark> option replaces the default name, which follows the pattern <mark style="color:blue;">"className"\_"fieldName"\_enum</mark>. It would be <mark style="color:blue;">user\_role\_enum</mark> in this case.
{% endhint %}

Now, generate and run the migration <mark style="color:orange;">add-role-to-user</mark>. Existing users will receive the <mark style="color:blue;">`USER`</mark> role.

<mark style="color:green;">**Commit**</mark> - Creating role enum
