supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.07k stars 209 forks source link

Local Dev supabase phone auth not working. Api Error. #1375

Closed djshubs closed 1 year ago

djshubs commented 1 year ago

I'm running into a similar issue as noted in #15570. I've setup the config as follow:

[auth.sms]
# Allow/disallow new user signups via SMS to your project.
enable_signup = true
# If enabled, users need to confirm their phone number before signing in.
enable_confirmations = true

# Configure one of the supported SMS providers: `twilio`, `messagebird`, `textlocal`, `vonage`.
[auth.sms.twilio.verify]
enabled = true
account_sid = "env(SUPABASE_AUTH_TWILIO_ACCOUNT_SID)"
message_service_sid ="env(SUPABASE_AUTH_TWILIO_MESSAGE_SERVICE_SID)" // maps to verify service ID
# DO NOT commit your Twilio auth token to git. Use environment variable substitution instead:
auth_token = "env(SUPABASE_AUTH_TWILIO_AUTH_TOKEN)"

Here's the error I'm getting:

AuthApiError: Error sending sms: sms Provider could not be found

Here's the function that gets trigger. Email is working perfectly.

const callbackURL = getURL() + 'auth/callback';

export async function signInWithOtp(data: z.infer<typeof signInWithOtpSchema>) {
  console.log({ data });
  const { email, phone, type, redirectTo } = signInWithOtpSchema
    .partial({ token: true })
    .parse(data);

  const redirectURL = `${callbackURL}${redirectTo ? '?' + redirectTo : ''}`;

  if (type === 'sms' && phone) {
    const { error } = await supabase.auth.signInWithOtp({
      phone,
      options: {
        shouldCreateUser: true,
      },
    });

    if (error) {
      console.error(error);
      redirect(`${getURL()}login?error=invalid_code`);
    }
    // URL to redirect to after sign in process completes
    redirect(redirectURL);
  }

  if (type === 'email' && email) {
    const { error } = await supabase.auth.signInWithOtp({
      email,
      options: {
        emailRedirectTo: redirectURL,
        shouldCreateUser: true,
      },
    });

    if (error) {
      console.error(error);
      redirect(`${getURL()}login?error=invalid_code`);
    }
  }
}

Packages:

    "supabase": "^1.85.0",
        "@supabase/auth-helpers-nextjs": "^0.7.4",
    "@supabase/auth-ui-react": "^0.4.2",
    "@supabase/supabase-js": "^2.32.0",

Originally posted by @djshubs in https://github.com/supabase/supabase/issues/15570#issuecomment-1675038438

azlekov commented 1 year ago

I'm must use Twilio Verify. When twilio-verify will be available in the CLI?

sweatybridge commented 1 year ago

This will be supported in the next stable release on 22 Aug. It's also available on cli beta release channel right now.

npx supabase@beta start
shawnmclean commented 1 year ago

Hey, while here, does anyone know how to get test credentials working with twilio verify so we don't use up credits?