在Supabase中更新用户认证信息。

huangapple go评论75阅读模式
英文:

update user authentication details in supabase

问题

我尝试使用Flask更新Supabase中的用户认证详细信息

这是我用于更新用户认证中的密码的方法

```python
supabase_client.auth.update_user({"id": email, "password": new_password})

首先,我从用户请求密码,然后在用户表和认证中进行更新。

以下是用于重置密码的路由:

@app.route('/reset', methods=['GET','POST'])
   def reset():
       if request.method == 'POST':
           try:
            email = request.form['email']
            new_password = request.form['new_password']
            # 在Supabase中的Users表中更新新密码
            user = supabase_client.auth.get_user()
            supabase_client.auth.update_user({"id": email, "password": new_password})
            supabase_client.from_('Users').update({'password': new_password}).eq('email', email).execute()
            flash('密码已更新')
            return render_template('login.html')

这是我用于重置密码的路由。但是,我遇到了API错误:

supabase_client.auth.update_user({"id": email, "password": new_password})

我只想知道是否我正在使用正确的方法,还有没有人知道如何在Flask中更新Supabase中的用户认证详细信息。


<details>
<summary>英文:</summary>

I try to update user authenticate details in supabase using flask. 

supabase_client.auth.update_user({"id": email,"password": new_password })


this is the am using to update the password in user authentication. First I request the password from user and then update that in Users table also in authentication.


```python
@app.route(&#39;/reset&#39;, methods=[&#39;GET&#39;,&#39;POST&#39;])
   def reset():
       if request.method == &#39;POST&#39;:
           try:
            email=request.form[&#39;email&#39;]
            new_password = request.form[&#39;new_password&#39;]
            #update new password in the supabase in table name Users
            user=supabase_client.auth.get_user()
            supabase_client.auth.update_user({&quot;id&quot;: email,&quot;password&quot;: new_password })
            supabase_client.from_(&#39;Users&#39;).update({&#39;password&#39;: new_password}).eq(&#39;email&#39;, email).execute()
            flash(&#39;password is updated&#39;)
            return render_template(&#39;login.html&#39;)

This is the route I used to reset the password. But am getting API error

supabase_client.auth.update_user({&quot;id&quot;: email,&quot;password&quot;: new_password })

I just want to know if I'm using the correct method or not, also if someone know how to update user authentication details in supabase using flask.

答案1

得分: 1

有两种更新用户数据的方式之一是:

supabase_client.auth.update_user({"id": email, "password": new_password })

但是对于这种方式,用户首先需要登录。例如,如果您想要更新用户的电子邮件,那么该用户首先需要登录,然后才能更新用户数据,否则将会出现错误。这种方法还会将电子邮件发送到新的电子邮件地址。但我在这方面遇到了一些问题:

  1. 它没有发送电子邮件到我的主要电子邮件地址。
  2. 它将电子邮件发送到新的电子邮件地址,并且在响应中显示已更新的电子邮件,但没有在数据库中更新它。

因此,我尝试了另一种方法,即:

supabase_client.auth.admin.update_user_by_id({"id": email, "password": new_password })

这种方法会在数据库中更新电子邮件,但需要...

继续...仍在努力,将会更新答案

英文:

There are two ways to update the user data one is:

supabase_client.auth.update_user({&quot;id&quot;: email, &quot;password&quot;: new_password })

but for this one, the user needs to be logged in first e.g. You want to update the user email, first that user need to be logged in after that it'll update the user data otherwise it will arise the error. This method also sends you the email to the new email address. But I have face some issues in that one:

  1. It didn't send me any email to my primary email
  2. It sends me email to the new email address and it also shows in the response the updated email but didn't update it on the database.

So, I tried another method which is:

supabase_client.auth.admin.update_user_by_id({&quot;id&quot;: email, &quot;password&quot;: new_password })

This one updates the email in the DB, but it requires.

Continue... Still working on it will update the Answer

huangapple
  • 本文由 发表于 2023年3月31日 19:03:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定