supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Cannot clear user phone number using `supabase.auth.admin.updateUserById` function

Open bombillazo opened this issue 10 months ago • 3 comments

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

Using the supabase.auth.admin.updateUserById and passing phone as an empty string, I would expect the phone value to be set to blank, passing null also give an API error

To Reproduce

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

  1. Setup your supabase client with admin priviledges
  2. call the supabase.auth.admin.updateUserById:
await supabase.auth.admin.updateUserById(
    userId,
    {  phone: '' }, // or  {  phone: null }
  );

Expected behavior

Phone is successfully cleard.

System information

  • Version of supabase-js: 2.42.0

Additional context

Add any other context about the problem here.

bombillazo avatar Apr 09 '24 16:04 bombillazo

It doesn't work on this either.

const { data, error } = await supabase.auth.updateUser({ phone: "" });

Is there any way around this?

dioveath avatar May 10 '24 13:05 dioveath

Might need to tag the maintainers to get some info/update

bombillazo avatar May 13 '24 13:05 bombillazo

Something like this could work

create or replace function clear_user_phone(user_id uuid)
    returns bool
    security definer
as
$$
begin
    update auth.users set phone = '',
                          phone_confirmed_at = null,
                          phone_change = ''
                      where id = user_id;
    return true;
end;
$$ language plpgsql;
const { data, error } = await supabase.rpc('clear_user_phone', {
	user_id: user.id,
})
if (error) {
	console.error(error)
}

unlocomqx avatar Aug 02 '24 21:08 unlocomqx