Lädt...


🔧 Using Supabase SMS-Hook to Send Custom Authentication Messages in India


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Given the limited support for local SMS providers in Supabase, the platform has introduced an auth hook that allows users to integrate their own local SMS or email providers for sending OTPs. This feature offers flexibility for those seeking to implement custom authentication solutions.
Follow these steps to set up a custom SMS hook for authentication in your Supabase project:

1. Access the Hooks Dashboard

2. Initiate Hook Creation

  • Click the "Add a new hook" button
  • Select "Send SMS hook" from the options

3. Configure Hook Settings

  • Toggle on "Enable Send SMS hook"
  • For Hook type, choose "HTTPS"

4. Set Up the Endpoint

  • In the URL endpoint field, enter: https://project_ref_id.supabase.co/functions/v1/sms-hook
  • Replace project_ref_id with your actual Supabase project reference ID

5. Generate and Save the Secret

  • Click on "Generate secret"
  • Copy the generated secret and store it securely

6. Create the Hook

  • Click "Create" to complete the setup

Implementing the SMS Hook Edge Function in Supabase

After setting up the custom SMS hook in your Supabase dashboard, the next step is to create and deploy an edge function that will handle the SMS sending logic. Follow these steps to implement the sms-hook function:

Prerequisites

  • Supabase CLI installed
  • Docker Desktop installed

Steps

1. Set Up Your Local Environment

a. Log in to Supabase CLI:

   npx supabase login

b. List your Supabase projects:

   npx supabase projects list

c. Link your local setup to your Supabase project:

   npx supabase link --project-ref your-project-id

2. Create the SMS Hook Function

Create a new function named "sms-hook":

   npx supabase functions new sms-hook

3. Implement the Function Logic

Open the index.ts file located at functions/sms-hook/index.ts and replace its content with the following code:

   import { Webhook } from "https://esm.sh/[email protected]";
   import { readAll } from "https://deno.land/std/io/read_all.ts";
   import * as base64 from "https://denopkg.com/chiefbiiko/base64/mod.ts";

   const sendTextMessage = async (
     messageBody: string,
     toNumber: string,
   ): Promise<any> => {
     const username = Deno.env.get("TEXT_GURU_USERNAME");
     const password = Deno.env.get("TEXT_GURU_PASSWORD");
     const source = Deno.env.get("SMS_HEADER");
     const tempId = Deno.env.get("SMS_TEMPLATE_ID");
     const url: string =
       `https://www.textguru.in/api/v22.0/?username=${username}&password=${password}&source=${source}&dmobile=${toNumber}&dlttempid=${tempId}&message=${messageBody}`;
     console.log("url:", url);
     const response = await fetch(url, {
       method: "POST",
       headers: {
         "Content-Type": "application/x-www-form-urlencoded",
       },
     });
     return response;
   };

   Deno.serve(async (req) => {
     const payload = await req.text();
     // Paste the earlier copied base64 secret here and remove the first "v1,whsec_" from the copied base64 secret
     const base64_secret = Deno.env.get("SEND_SMS_HOOK_SECRET");
     const headers = Object.fromEntries(req.headers);
     const wh = new Webhook(base64_secret);
     try {
       const { user, sms } = wh.verify(payload, headers);
       const messageBody =
         `Dear Customer, Your Verification Code For Company name Is ${sms.otp}. Please do Not share this Code with anyone.`;
       const response = await sendTextMessage(
         messageBody,
         user.phone,
       );
       // You can edit further code as the response coming from your sms provider
       if (response.statusText === "OK") {
         return new Response(
           JSON.stringify({ message: "SMS sent successfully." }),
           {
             status: 200,
             headers: {
               "Content-Type": "application/json",
             },
           },
         );
       }
       return new Response(
         JSON.stringify({
           error: {
             http_code: response.status,
             message:
               `Failed to send SMS: ${response.message}. More info: ${response.more_info}`,
           },
         }),
         {
           status: response.status,
           headers: {
             "Content-Type": "application/json",
           },
         },
       );
     } catch (error) {
       return new Response(
         JSON.stringify({
           error: {
             http_code: 500,
             message: `Failed to send sms: ${JSON.stringify(error)}`,
           },
         }),
         {
           status: 500,
           headers: {
             "Content-Type": "application/json",
           },
         },
       );
     }
   });

4. Deploy the Function

Deploy the sms-hook function using the following command:

   npx supabase functions deploy sms-hook --no-verify-jwt

5. Enable Phone Authentication

Remember to enable the phone provider from Authentication Providers in your Supabase Dashboard.

Important Notes

  • Make sure to replace placeholders like your-project-id with your actual Supabase project details.
  • The SEND_SMS_HOOK_SECRET should be set as an environment variable, using the secret you generated earlier (remove the v1,whsec_ prefix).
  • You'll need to set up environment variables for TEXT_GURU_USERNAME, TEXT_GURU_PASSWORD, SMS_HEADER, and SMS_TEMPLATE_ID according to your SMS provider's requirements.
  • This implementation uses TextGuru as the SMS provider. You may need to adjust the sendTextMessage function if you're using a different provider.

By following these steps, you'll have successfully implemented and deployed a custom SMS hook for authentication in your Supabase project.

...

🔧 Setup User Auth for your Reflex Python app using supabase (supabase-py)


📈 35.33 Punkte
🔧 Programmierung

🔧 Send SMS Messages with Cloud Functions For Firebase Gen 2


📈 28.1 Punkte
🔧 Programmierung

📰 Android Users Can Now Send SMS Messages from Windows 10


📈 28.1 Punkte
📰 IT Security Nachrichten

📰 Improper Input Validation | Add Custom Text and URLs In SMS send by Snapchat | Bug Bounty POC


📈 26.72 Punkte
📰 IT Security Nachrichten

🍏 DRPU Bulk SMS 10.2.4.4 - Mac SMS Software broadcast unlimited notifications and standard text messages.


📈 26.67 Punkte
🍏 iOS / Mac OS

📰 SpamHound SMS Spam Filter - Get rid of spam SMS messages!


📈 26.67 Punkte
📰 IT Security Nachrichten

🔧 Add password-less OTP based authentication to your Next.js apps using Supabase & Twilio


📈 24.79 Punkte
🔧 Programmierung

🔧 How To Send Emails Using Cloud Functions, Firestore & Firebase-Send-Email


📈 24.7 Punkte
🔧 Programmierung

🔧 How To Send Emails Using Cloud Functions, Firestore & Firebase-Send-Email


📈 24.7 Punkte
🔧 Programmierung

📰 Send | Share Self-Destructing File Online FREE Using Firefox Send


📈 24.7 Punkte
📰 Alle Kategorien

🔧 Using ChatGPT with Your Own Data using LangChain and Supabase


📈 23.77 Punkte
🔧 Programmierung

🔧 How to Create a Telegram Bot and Send Messages Using Laravel 11


📈 23.29 Punkte
🔧 Programmierung

🔧 Send messages to the client in real time using NodeJS and Server-Sent Events


📈 23.29 Punkte
🔧 Programmierung

🍏 How to schedule messages in iOS 18 using 'Send Later'


📈 23.29 Punkte
🍏 iOS / Mac OS

🔧 Step-by-Step Guide on How to Send Error Messages from Laravel App to Slack Using Webhooks


📈 23.29 Punkte
🔧 Programmierung

🐧 How To Send Messages With The Bitcoin Blockchain On Linux Using Bitmessage


📈 23.29 Punkte
🐧 Linux Tipps

📰 How To Send Messages With The Bitcoin Blockchain On Linux Using Bitmessage


📈 23.29 Punkte
🖥️ Betriebssysteme

🕵️ Hackers Using Android Malware to Compromise Diabetic Patients Android Devices To Send Premium SMS


📈 23.27 Punkte
🕵️ Hacking

🔧 Add AWS SES as custom SMTP provider to Supabase


📈 23.15 Punkte
🔧 Programmierung

🔧 Building a Custom Chatbot with Next.js, Langchain, OpenAI, and Supabase.


📈 23.15 Punkte
🔧 Programmierung

🕵️ National Payments of India BHIM 1.3 on Android SMS Validation weak authentication


📈 23.09 Punkte
🕵️ Sicherheitslücken

🕵️ Malicious Apps from Google PlayStore Bypassing SMS-Based Two-Factor Authentication and Steal OTPs in SMS


📈 22.86 Punkte
🕵️ Hacking

📰 Out of Band Phishing. Using SMS messages to Evade Network Detection, (Thu, Aug 19th)


📈 21.86 Punkte
📰 IT Security

🔧 Building a Modern Authentication System with Supabase, Ballerina, and Next.js


📈 20.71 Punkte
🔧 Programmierung

🔧 Building a Nuxt.js + Vue.js SaaS Starter: Authentication, Payments, and Supabase Made Easy


📈 20.71 Punkte
🔧 Programmierung

🔧 Handling Authentication with Supabase, Analog and tRPC


📈 20.71 Punkte
🔧 Programmierung

🔧 How to Set Up Authentication in Your Apps with Supabase Auth


📈 20.71 Punkte
🔧 Programmierung

🔧 How to build a Telegram Bot that Send Quote after every 10 Send


📈 20.62 Punkte
🔧 Programmierung

🍏 Send to Kindle 1.1.1.254 - Send your personal documents to your Kindle.


📈 20.62 Punkte
🍏 iOS / Mac OS

🐧 Heard you can send pictures in the comments now. Send pics of Linux setups


📈 20.62 Punkte
🐧 Linux Tipps

matomo