What would be the best way to create an isAuthor guard for nestjs?

Viewed 50

I have been taking online course from udemy and playing around with the guard middleware

I also created the admin.guard auth.guard suggested by following the tutorial but I am thinking what if I want to add an isAuthor.guard that not only the admin can make changes to post or whatever but the original author is also able to make edits...

What would be a better way to create this? Should it be a guard? or middleware would be better?

P.S. I tried accessing services through guard with this post Inject service into guard in Nest.JS but didn't work for me.

Edit: Also, is it possible to have or guards? For example isAdmin / isAuthor so it can be used flexible instead of having a isAdminOrAuthor

Thanks in advance for any suggestions / advices.

0 Answers
Related