supabase icon indicating copy to clipboard operation
supabase copied to clipboard

Be aware when calling signUp on the server side

Open oripka opened this issue 1 year ago • 1 comments

I had code like this on the server side in an event handler. That failed the second request. The issue was, that signUp apparently assumes the role of the user that just signed up and so in the second request I don't have enough permissions. Just something to be aware of and maybe add to the docs.

import { serverSupabaseServiceRole } from '#supabase/server'
const client = serverSupabaseServiceRole<Database>(event)
const { data, error } = await client.auth.signUp({
  email: email,
  password: randomPassword,
})

const { data: vouchers, error } = await client
  .from('vouchers')
  .select('courseid, id')
  .eq('voucher', voucher)

The fix is to call signout after signUp to revert back to the service role.

// so we need to sign out
await client.auth.signOut()

oripka avatar Jul 24 '24 13:07 oripka

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar May 06 '25 13:05 github-actions[bot]