Role
Defines a user's permissions.
We'll store the possible roles for a user in an enum. So first, create the file auth/roles/enums/role.enum with following content.
export enum Role {
ADMIN = 'ADMIN',
MANAGER = 'MANAGER',
USER = 'USER',
}
Now, let's go back to the User
entity and declare a role
for it. This is how we can map an enum to the database. Also notice the default
value.
@Column({
type: 'enum',
enum: Role,
enumName: 'role_enum',
default: Role.USER,
})
role: Role;
Now, generate and run the migration add-role-to-user. Existing users will receive the USER
role.
Commit - Creating role enum
Last updated