Skip to content

Commit

Permalink
Feat: Added permission/authorization section to RAEDME
Browse files Browse the repository at this point in the history
  • Loading branch information
namdao2000 authored Aug 24, 2022
1 parent d1c992a commit 4f963e4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ Use the `getToken` method from `NextAuth` to verify the validity of the user's `

If the token is outdated or is tampered with, it will return null.

### **Permission / Authorization**
If a user tries to do a privileged action, make sure that they have enough permission to do it.

In my example here, a user can only delete a product if it BELONGS to them. So I do a check with prisma to make sure that its the case.

```ts
async updateOneProduct(
...
) {
prisma.product.updateMany({
where: {
id: where.id,
userId: where.userId, // <-- Check to make sure that the user is authorized to make such action.
},
...
});
}
```

### **Signin / Signout**
`NextAuth` provides us with 2 useful functions for the frontend.

Expand Down

0 comments on commit 4f963e4

Please sign in to comment.