当我想让经过身份验证的用户更改其电子邮件地址时,我使用 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.
发布评论
评论(2)
我遇到了类似的问题,就我而言,它归结为 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.
From the Supabase docs for
supabase.auth.update
: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!
这正是我的问题。然而,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