Supabase auth.update() email_refresh_token 工作流程

发布于 2025-01-10 05:34:26 字数 1643 浏览 6 评论 0 原文

当我想让经过身份验证的用户更改其电子邮件地址时,我使用 auth.update(),可在此处找到 https://supabase.com/docs/reference/javascript/auth-update

我只使用魔术链接身份验证,顺便说一句。

现在我的项目设置为仅需要一封电子邮件确认。

我使用 vue 3 和 vu-router v4

当我运行此函数时,

 async handleUpdateUser(newEmail: string) {
      try {
        const { user, error } = await supabase.auth.update({
          email: newEmail,
        });

        if (error) throw error;
      } catch (error) {
        console.log(error);
      }
    },

我记录的 onAuthStateChange 显示为 USER_UPDATED,服务器上的 users.auth 表显示新内容,并且在控制台中的 user 对象上看到 new_email

属性问题是如何将 new_emial 变成电子邮件。

发送到新电子邮件的链接如下

https:// Correct_info_is_here.supabase.co/auth/v1/verify?token=there_is_a_token_here&type=email_change&redirect_to=http://localhost:3000/

当我单击链接时,它会重定向到一个新窗口,就像初始注册时一样,但除此之外没有任何变化。

我找到了这个答案, https://github.com/supabase/supabase/discussions/1763

但我有不知道如何实施该程序。弄清楚如何获取该令牌的唯一方法是通过客户端上的 rpc 函数,但我不知道收到该令牌后如何处理该令牌。

另外,我可能会补充说,当我使用 vue-router 时,我会记录 beforeEach 的 to 和 from 属性,就像这样

router.beforeEach(async (to, from) => {
  console.log("to", to);
  console.log("from", from);...

当我加载确认链接时,它不会像从原始注册链接重定向时那样显示任何有用的内容。

任何帮助将不胜感激。

When I want to let an authenticated user change their email address I use auth.update(), found here https://supabase.com/docs/reference/javascript/auth-update

I'm using just a magic link auth, btw.

Right now my project is set up for only one email confirmation.

Im using vue 3 with vu-router v4

When I run this function

 async handleUpdateUser(newEmail: string) {
      try {
        const { user, error } = await supabase.auth.update({
          email: newEmail,
        });

        if (error) throw error;
      } catch (error) {
        console.log(error);
      }
    },

The onAuthStateChange that I log shows as USER_UPDATED, the users.auth table on the server shows the new stuff, and a new_email prop is seen on the user object in the console

My question is how do I make the new_emial into just email.

the link that is sent to the new email is as so

https://correct_info_is_here.supabase.co/auth/v1/verify?token=there_is_a_token_here&type=email_change&redirect_to=http://localhost:3000/

When I click the link, it redirects to a new window just like it does when an initial sign up happens, but other than that nothing changes.

I found this answer,
https://github.com/supabase/supabase/discussions/1763

but I have no idea how to implement that procedure. The only way figured out how to get that token is by an rpc function on the client , but I don't know what to do with that token after I receive it.

Also I might add when I use vue-router, I log the to and from properties of the beforeEach like so

router.beforeEach(async (to, from) => {
  console.log("to", to);
  console.log("from", from);...

When I load the confirmation link, it doesn't show anything useful like it does when its redirected form the original sign up link.

Any help would greatly be appreciated.

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

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

发布评论

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

评论(2

依 靠 2025-01-17 05:34:26

我遇到了类似的问题,就我而言,它归结为 Supabase Studio 中的“双重确认电子邮件更改”设置。

来自 supabase.auth.update 的 Supabase 文档:

默认情况下,电子邮件更新将向用户的当前电子邮件地址和新电子邮件地址发送一封带有确认链接的电子邮件。要关闭此行为并仅向新电子邮件发送单个确认链接,请在“身份验证”下切换“双重确认电子邮件更改”-> “设置”关闭。

因此,可能发生的情况是,当您请求更改电子邮件时,用户会收到两封电子邮件:一封是旧电子邮件地址,另一封是新电子邮件地址。 用户必须单击这两个链接才能真正更新该用户的电子邮件列。

至少,这是我的案例中的问题 - 我希望它有所帮助!

I ran into a similar issue, and in my case, it came down to the "Double confirm email changes" setting in Supabase Studio.

"Double confirm email changes" setting

From the Supabase docs for supabase.auth.update:

Email updates will send an email to both the user's current and new email with a confirmation link by default. To toggle this behavior off and only send a single confirmation link to the new email, toggle "Double confirm email changes" under "Authentication" -> "Settings" off.

So what may be happening is that when you request the email change, the user receives two emails: one at the old email address, and one at the new email address. The user must click both links in order for that user's email column to actually be updated.

At least, this was the issue in my case — I hope it helps!

那片花海 2025-01-17 05:34:26

这正是我的问题。然而,supabase 中的 UI 更改意味着它现在位于“providers >”之下。电子邮件>安全的电子邮件更改。

关闭supabase中的电子邮件双重验证

This was exactly my problem. However, the UI change in supabase means its now under providers > email > secure email change.

turning off email double verification in supabase

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