Home > Mobile >  Remove ability to edit data if person refreshes page / visits from another tab?
Remove ability to edit data if person refreshes page / visits from another tab?

Time:06-07

imgur has an interesting feature where

  • you can create a post using https://imgur.com/upload
  • after the upload finishes, you will be redirected to the post's page where you can edit the title as much as you want. If you refresh the page / visit it in another tab--the ability to edit the title is gone.

How is Imgur doing this? My guess is cookies are involved somehow, but I'm not sure.

CodePudding user response:

On Create save the id of the editable resource, on Render if it matches enable edit and reset the saved editable id.

    return redirect(`resource/$id`, {
         headers: {
          "Set-Cookie":  `editable:$id`,
         },
    });

Then, use the Cookie API to check that cookie.

CodePudding user response:

If you do not want to use cookies or session than one way to achieve this is by using useState. update the state when post is created/upload to true(initially false). When user will refresh the page then that state will automatically be false because the component is rendered just now. Note:- If you do not want to use state you can use redux also to achieve this solution. After that use that state or redux state to to enable/disable the ability to edit the post.

  • Related