Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
Conditional component render if user is an owner of post React + Django Rest Framework

I have f.e. User and Post models. User object has an id and Post object has owner id. I want to render the <Edit /> button just when User is the owner of the Post. What is the best way to do this?

Simply I can just get the current User id from database using one of my django's endpoints and check if (user.id === post.owner) but is it the best way?

Also how can I block or redirect users which are not the owner if someone of them open the editing site by link. Should I also simply check if if user.id === post.owner?

One extra question: I am storing my JWT tokens at the moment in the localStorage. What should I looking for if I want to hide it in my blowser (if I click F12, I can find it in Application tab)?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could offload the checking to the Edit Component sending the user.id to it (it should have post.owner) then handling that inside the Edit component.

To avoid people directly accessing the edit link, there many different options to prevent or make it harder, here are two simple ones:

  1. Use useEffect hook on page load and checking that, if not authorized redirect to previous page
  2. Randomizing the url so it's not the same each time
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda