rauth-provider
Version:
A lightweight, plug-and-play Node.js library for phone number authentication using the Rauth.io reverse verification flow via WhatsApp or SMS.
65 lines (59 loc) • 2.57 kB
JavaScript
/**
* RauthProvider - A clean, plug-and-play authentication library
*
* This library provides automated session management for phone number verification
* with webhook support for real-time session updates.
*
* @example
* const { RauthProvider } = require('rauth-provider');
*
* RauthProvider.init({
* rauth_api_key: process.env.RAUTH_API_KEY,
* app_id: process.env.RAUTH_APP_ID,
* webhook_secret: process.env.RAUTH_WEBHOOK_SECRET,
* });
*
* app.post('/rauth/webhook', RauthProvider.webhookHandler());
*/
const RauthProvider = require('./core/RauthProvider');
let RauthServer = require('./server');
if (!RauthServer || (typeof RauthServer !== 'function' && typeof RauthServer !== 'object')) {
// Try default export (in case of ES module interop)
RauthServer = require('./server').default;
}
if (!RauthServer) {
throw new Error('rauth-provider: Failed to import RauthServer. This may be due to a Node.js version or module system incompatibility.');
}
const SessionStore = require('./core/sessionStore');
const RevokedStore = require('./core/revokedStore');
const Utils = require('./core/utils');
const RauthApiClient = require('./core/apiClient');
/**
* Main export object with all RauthProvider functionality
*/
module.exports = {
// Main provider instance
RauthProvider,
// Server utilities for Express integration
RauthServer,
// Core components (for advanced usage)
SessionStore,
RevokedStore,
Utils,
RauthApiClient,
// Convenience aliases
init: RauthProvider.init.bind(RauthProvider),
initSession: RauthProvider.initSession.bind(RauthProvider),
verifySession: RauthProvider.verifySession.bind(RauthProvider),
isSessionRevoked: RauthProvider.isSessionRevoked.bind(RauthProvider),
webhookHandler: RauthProvider.webhookHandler.bind(RauthProvider),
clearAllSessions: RauthProvider.clearAllSessions.bind(RauthProvider),
// Server utilities
setupRoutes: RauthServer.setupRoutes?.bind(RauthServer),
createWebhookHandler: RauthServer.createWebhookHandler?.bind(RauthServer),
createHealthCheckHandler: RauthServer.createHealthCheckHandler?.bind(RauthServer),
createSessionInitHandler: RauthServer.createSessionInitHandler?.bind(RauthServer),
createSessionVerificationHandler: RauthServer.createSessionVerificationHandler?.bind(RauthServer),
createRevocationCheckMiddleware: RauthServer.createRevocationCheckMiddleware?.bind(RauthServer),
createStatsHandler: RauthServer.createStatsHandler?.bind(RauthServer),
};