Skip to content

updateUser vs admin.updateUserById behavior with Anonymous Users #1578

Description

@r-southworth

Bug report

  • [ X ] I confirm this is a bug with Supabase, not with my own application.
  • [ X ] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

There is no way to convert an anonymous user to a permanent user without sending a confirmation email. updateUser and admin.updateUserById have inconsistent behavior

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Run command server side using an anonymous user_id:
const { data, error } = await supabase.auth.admin.updateUserById(user_id, {
      email: response.email, 
      email_confirm: true,
  })
  1. Resulting user:
{
  "instance_id": "00000000-0000-0000-0000-000000000000",
  "id": "5b0c50f8-bd4d-4815-a21e-b67486593073",
  "aud": "authenticated",
  "role": "authenticated",
  "email": "test55@test.com",
  "encrypted_password": "",
  "email_confirmed_at": "2024-05-07 15:52:39.207944+00",
  "invited_at": null,
  "confirmation_token": "",
  "confirmation_sent_at": null,
  "recovery_token": "",
  "recovery_sent_at": null,
  "email_change_token_new": "",
  "email_change": "",
  "email_change_sent_at": null,
  "last_sign_in_at": "2024-05-07 15:26:46.873409+00",
  "raw_app_meta_data": {},
  "raw_user_meta_data": {},
  "is_super_admin": null,
  "created_at": "2024-05-07 15:26:46.865084+00",
  "updated_at": "2024-05-07 15:52:39.212126+00",
  "phone": null,
  "phone_confirmed_at": null,
  "phone_change": "",
  "phone_change_token": "",
  "phone_change_sent_at": null,
  "confirmed_at": "2024-05-07 15:52:39.207944+00",
  "email_change_token_current": "",
  "email_change_confirm_status": 0,
  "banned_until": null,
  "reauthentication_token": "",
  "reauthentication_sent_at": null,
  "is_sso_user": false,
  "deleted_at": null,
  "is_anonymous": true
}

Expected behavior

I would expect

const { data, error } = await supabase.auth.admin.updateUserById(user_id, {
      email: response.email, 
      email_confirm: true,
  })

called from the server to convert a user from anonymous to email with no need for a confirmation email.

Currently that call adds the email address AND confirms the user but leaves them as provider = anonymous which makes it impossible to set a password for the user.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: MacOS
  • Browser (if applies) Chrome but N/A I think in this case
  • Version of supabase-js: 2.42.0
  • Version of Supabase CLI - 1.165.0
  • Version of Node.js: 20.11.1

Additional context

The only documented way to change the user from anonymous that I am aware of is listed here: https://supabase.com/docs/guides/auth/auth-anonymous

It seems to require email confirmations.

Regardless of the local setting for auth.email.enable_confirmations using the supabase.auth.updateUser sends the standard email confirmation to the user.

If I have anonymous users I might want to store their information for future reference (ecommerce guest checkout with downloadable products) but since they did not choose to make an account I shouldn't be emailing them about an account AND there is no way to send them a different email than the standard confirmation email. The typical way around sending a confirmation email without turning off email confirmation is to do server side supabase.auth.admin.updateUserById however in this case it doesn't convert the user provider from Anonymous and there doesn't seem to be any documentation on how to change that in any other way.

More details can be found here: https://discord.com/channels/839993398554656828/1237139614486233119

Metadata

Metadata

Assignees

No one assigned

    Labels

    authbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions