Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda