feat: add contact form with SMS OTP verification
This commit is contained in:
parent
91b162fb44
commit
3874443c34
14 changed files with 729 additions and 54 deletions
42
server/lib/sms-gateway.js
Normal file
42
server/lib/sms-gateway.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import Client from "android-sms-gateway";
|
||||
import { httpFetchClient } from "./http-client";
|
||||
|
||||
/**
|
||||
* Creates and configures an instance of the android-sms-gateway client.
|
||||
* It centralizes the client instantiation and ensures that all necessary
|
||||
* configuration for the gateway is present.
|
||||
*
|
||||
* @param {object} config The runtime configuration object from `useRuntimeConfig`.
|
||||
* It should contain `androidSmsGatewayLogin`, `androidSmsGatewayPassword`,
|
||||
* and `androidSmsGatewayUrl`.
|
||||
* @returns {Client} A configured instance of the SMS gateway client.
|
||||
* @throws {Error} If the required gateway configuration is missing, prompting
|
||||
* a 500-level error in the calling API endpoint.
|
||||
*/
|
||||
export function createSmsGatewayClient(config) {
|
||||
const {
|
||||
androidSmsGatewayLogin,
|
||||
androidSmsGatewayPassword,
|
||||
androidSmsGatewayUrl,
|
||||
} = config;
|
||||
|
||||
if (
|
||||
!androidSmsGatewayLogin ||
|
||||
!androidSmsGatewayPassword ||
|
||||
!androidSmsGatewayUrl
|
||||
) {
|
||||
console.error(
|
||||
"SMS Gateway service is not configured. Missing required environment variables for the gateway.",
|
||||
);
|
||||
// This indicates a critical server misconfiguration. The calling API endpoint
|
||||
// should handle this and return a generic 500 error to the client.
|
||||
throw new Error("Server is not configured for sending SMS.");
|
||||
}
|
||||
|
||||
return new Client(
|
||||
androidSmsGatewayLogin,
|
||||
androidSmsGatewayPassword,
|
||||
httpFetchClient,
|
||||
androidSmsGatewayUrl,
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue