Auth behavior after deleting users
# help-and-questions
l
Firstly I created a user, then for testing purposes I deleted this user from console, and create user with same mail again from my app. This is where it going weird, After creating user again, I get user object and there seems no error:
Copy code
{
  id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
  aud: 'authenticated',
  role: 'authenticated',
  email: 'someEmail@gmail.com',
  email_confirmed_at: '2023-05-20T21:21:03.322059064Z',
  phone: '',
  app_metadata: {
    has_active_subscription: false,
    provider: 'email',
    providers: [ 'email' ]
  },
  user_metadata: {},
  identities: [
    {
      id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
      user_id: 'bcede112-7d3e-4c49-9ab6-5101842f2a15',
      identity_data: [Object],
      provider: 'email',
      last_sign_in_at: '2023-05-20T21:21:03.319379632Z',
      created_at: '2023-05-20T21:21:03.319427Z',
      updated_at: '2023-05-20T21:21:03.319427Z'
    }
  ],
  created_at: '2023-05-20T21:21:03.317314Z',
  updated_at: '2023-05-20T21:21:03.322296Z'
}
but when I try to log this user, boom there is no user. Because its never created, doesn't appear on console too.
Copy code
const {data: {user}, error} = await supabase.auth.admin.createUser({
    email: userEmail,
    password: userPassword,
    email_confirm: true,
    app_metadata: {
      has_active_subscription: false,
    },
  })
this is how I create user on server side
g
How did you delete the user?
l
from dashboard console auth section

https://cdn.discordapp.com/attachments/1111216933673635920/1111315827921268756/Screenshot_2023-05-25_at_17.32.14.png

g
OK. Just making sure you did not delete the row in auth.users as there are other tables that have email info in them.
l
no not from tables
g
You might check the identities table and see if there is still an entry with that email in it. To me that would be a bug if the delete did not clean up everything. And likely a new bug as I have used the same user over and over again... but use signUp not createUser.
Also can you use add user in that same auth UI as you did the delete. Up at top right.
l
identities table cleaned
it created from dashboard
with no problem
g
OK so not a delete issue, but something going wrong with your createClient with no error...
If you create with a different email does it work from your createClient code?
l
yes
if I try a new (previously not deleted from console) email, then it created and login all without issue
but if I delete this new email from console then try to register it again, problem starts
g
Very strange the add user works and createUser does not. You probably should generate an issue in supabase/gotrue github (and see if an issue already exists).
I can't think of a way your code could cause this with two different emails getting different results.
I guess you could also look at Postgres and Auth logs just to make sure there was not an error that did not get reported out.
s
Did you use your
service_role
key when creating the user?
l
yes
Copy code
const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.PRIVATE_SERVICE_ROLE!,
    {
      auth: {
        autoRefreshToken: false, 
        persistSession: false,
      },
    },
  )