Next.js Discord

Discord Forum

Is it safe to pass session to a component?

Unanswered
Brewer's Blackbird posted this in #help-forum
Open in Discord
Brewer's BlackbirdOP
I have a comments list component and a comment component. I want to check if user can delete the comment:"
{author.id === session.user.id && <CommentMenu />}


I also tried to create a permissions object:
getComments function
    const session = await getServerAuthSession();
    const permissions: Record<string, boolean> = {};

    for (const comment of comments) {
      if (
        session?.user.id === comment.author.id ||
        session?.user.role === "ADMIN"
      ) {
        permissions[comment.id] = true;
      } else {
        permissions[comment.id] = false;
      }
    }


But is there any beter way to do this?

1 Reply

Toyger
it's good, but just be sure that you checking again for permissions on backend where main logic of removing comment from database will execute.