如果人从另一个选项卡中刷新页面 /访问,请删除编辑数据的能力?

发布于 2025-01-31 18:52:13 字数 363 浏览 5 评论 0原文

imgur 具有一个有趣的功能,

  • 您可以在其中使用 https://imgur.com/upload
  • 上传完成后,您将被重定向到帖子的页面,在那里您可以根据需要编辑标题。如果您在另一个选项卡中刷新页面 /访问它 - 编辑标题的能力已经消失。

Imgur如何做到这一点? 我的猜测是饼干有点涉及,但我不确定。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷清清 2025-02-07 18:52:14

如果您不想使用cookie或会话,而不是一种方法来实现这一目标。创建发布/上传到true(最初为false)时更新状态。当用户刷新页面时,该状态将自动为false,因为该组件刚刚呈现。
注意: - 如果您不想使用状态,则可以使用Redux来实现此解决方案。
之后,使用该状态或REDUX状态以启用/禁用编辑帖子的能力。

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.

电影里的梦 2025-02-07 18:52:13

实现此目的/docs/hooks-state.html“ rel =“ nofollow noreferrer”> usestate 在创建create保存可编辑资源的ID上

  • ,如果它匹配启用编辑并重置保存的可编辑ID,则在渲染中实现这一目标。

    您可以伪造重定向,这意味着显示编辑页面并将视图页面放入URL

  • 重定向时,设置cookie: https://remix.run/docs/en/v1/api/remix#redirect

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

然后,使用 cookie api 检查该饼干。

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.

是伱的 2025-02-07 18:52:13

您可以检查导航类型。请参阅 @ @ @зleshref =“ https://stackoverflow.com/a/53307588/14250290”> href = on @

极寻找重新加载back_forward您可能想在后端发生某些事情,以防止恶意用户。

另一个选择是在进行帖子时从后端发送令牌,并为了编辑帖子,需要将确切的令牌发送回去。只是不要将令牌保存在持续存在的任何东西中,并在刷新或新选项卡中保存。

you can check for the navigation type. see the answer from @Илья Зеленько on https://stackoverflow.com/a/53307588/14250290

the types you're looking for are reload and back_forward you probably want to have something happen in the backend happen as well to prevent a malicious user.

Another option would be to send a token from the backend when a post is made and in order to edit a post that exact token would need to be sent back. Just don't save the token in anything that persists and on a refresh or new tab it'll be yeeted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文