remix-auth-twilio
Version:
Uses the [Twilio Verify API](https://www.twilio.com/verify) to validate users via SMS and add simple phone-based auth to a [Remix](https://remix.run) application using [Remix Auth](https://github.com/sergiodxa/remix-auth).
71 lines (70 loc) • 2.34 kB
TypeScript
import { SessionStorage } from "@remix-run/server-runtime";
import { AuthenticateOptions, Strategy, StrategyVerifyCallback } from "remix-auth";
import { VerificationInstance } from "twilio/lib/rest/verify/v2/service/verification";
import { VerificationCheckInstance } from "twilio/lib/rest/verify/v2/service/verificationCheck";
type SendCodeFunction = ({ phone, }: {
phone: string;
}) => Promise<VerificationInstance>;
type ValidateCodeFunction = ({ code, phone, }: {
code: string;
phone: string;
}) => Promise<VerificationCheckInstance>;
type FormatPhoneNumberFunction = (phone: string) => string;
export type TwilioStrategyOptions = {
/**
* Twilio Account SID
*/
accountSID: string;
/**
* Twilio Auth Token
*/
authToken: string;
/**
* Twilio Verify Service SID
*/
serviceSID: string;
/**
* A function that sends a verification code to the user.
*/
sendCode?: SendCodeFunction;
/**
* A function that validates the verification code provided by the user.
*/
validateCode?: ValidateCodeFunction;
/**
* A function that formats the phone number provided by the user.
* This library uses the `phone` package to validate phone numbers.
* You can optionally provide your own validation function here.
*/
formatPhoneNumber?: FormatPhoneNumberFunction;
};
export interface TwilioStrategyParams {
/**
* The phone number provided by the user.
*/
phone: string;
/**
* A FormData object that contains the form
* used to trigger the authentication.
*/
formData: FormData;
/**
* The Request object.
*/
request: Request;
}
export declare class TwilioStrategy<User> extends Strategy<User, TwilioStrategyParams> {
name: string;
private readonly sessionPhoneKey;
private readonly client;
private readonly options;
private readonly sendCode;
private readonly validateCode;
private readonly formatPhoneNumber;
constructor(options: TwilioStrategyOptions, verify: StrategyVerifyCallback<User, TwilioStrategyParams>);
authenticate(request: Request, sessionStorage: SessionStorage, options: AuthenticateOptions): Promise<User>;
private defaultSendCode;
private defaultValidateCode;
private defaultFormatPhoneNumber;
}
export {};