Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be aware when calling signUp on the server side #395

Open
oripka opened this issue Jul 24, 2024 · 0 comments
Open

Be aware when calling signUp on the server side #395

oripka opened this issue Jul 24, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@oripka
Copy link

oripka commented Jul 24, 2024

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 oripka added the bug Something isn't working label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant