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

updateUserById - user_id must be an UUID

Open WilliamFalci opened this issue 3 years ago • 7 comments

Bug report

Describe the bug

invoke functionuser_id must be an UUID return ​user_id must be an UUID

To Reproduce

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

  1. Create a file "test.js" and copy this code:
const {createClient} = require('@supabase/supabase-js')
require('dotenv').config()


const options = {
  schema: 'public',
  headers: {},
  autoRefreshToken: true,
  persistSession: true,
  detectSessionInUrl: true
}

const supabase = createClient("http://localhost:8000", process.env.SERVICE_ROLE_KEY, options)

async function createUsers(){
  const { data: admin, errorADMIN } = await supabase.auth.api.createUser({
    email: '[email protected]',
    password: 'password',
    data: { name: 'Test Admin' }
  })
  
  if(!errorADMIN){
    console.log('> User: [email protected] - Created',admin)

    const test = await supabase.auth.api.updateUserById({
      uid: admin.id,
      attributes: { email_confirm: true },
    })

    console.log('##### TEST', test)
  }else{
    console.log(errorADMIN)
  }
  
  
  const { data: user, errorUSER } = await supabase.auth.api.createUser({
    email: '[email protected]',
    password: 'password',
    data: { name: 'Test User' },
    attributes: { email_confirm: true },
  })
  
  if(!errorUSER){
    console.log('> User: [email protected] - Created',user)
    const test2 = await supabase.auth.api.updateUserById({
      uid: user.id,
      attributes: { email_confirm: true },
    })
    console.log('##### TEST', test2)
  }else{
    console.log(errorUSER)
  }
}

createUsers()

Replace fix env / urls to be in the same page with ur setup

Expected behavior

I expect to update the user with the uid returned by createUser function

Screenshots

image

System information

  • OS: Windows 11
  • Version of supabase-js: 1.30
  • Version of Node.js: 14

WilliamFalci avatar Feb 11 '22 22:02 WilliamFalci

I'm having the same issue here.

ngerritsen avatar Feb 23 '22 08:02 ngerritsen

+1 also getting the same error

impactvelocity avatar Feb 26 '22 19:02 impactvelocity

Solution I am using (seems to work), if you are wanting to create a user and have them confirmed without the user having to do anything. Instead of createUser and updateUserById, I just called auth.signUp from the server with their email and password. That seems to work.

impactvelocity avatar Feb 26 '22 20:02 impactvelocity

Solution I am using (seems to work), if you are wanting to create a user and have them confirmed without the user having to do anything. Instead of createUser and updateUserById, I just called auth.signUp from the server with their email and password. That seems to work.

Already knew but... are different concepts, the signUp will create the user and set the supabase istance with the user auth, the createUser go to create the user without set the auth

WilliamFalci avatar Feb 27 '22 21:02 WilliamFalci

+1 having this issue as well

limmidy avatar Feb 28 '22 00:02 limmidy

+1 having this issue as well

pbrvn avatar Mar 02 '22 21:03 pbrvn

@kiwicopple this is the right repository for this bug?

WilliamFalci avatar Mar 07 '22 23:03 WilliamFalci

Hey @WilliamFalci, @limmidy, @impactvelocity, @ngerritsen, this isn't a bug with the client library. Based on the example @WilliamFalci provided above, the uid is being passed incorrectly in updateUserById. See the updateUserById method.

// Incorrect
const test = await supabase.auth.api.updateUserById({
      uid: user.id,
      attributes: { email_confirm: true },
    })

// Correct 
const test = await supabase.auth.api.updateUserById(user.id, {
  email_confirm: true,
})

Will be closing this issue since it's not an issue with the client library. Please let me know if you guys still have any questions regarding this issue.

kangmingtay avatar Sep 30 '22 05:09 kangmingtay