Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!