Skip to main content

Add Phone Authentication to Your Node.js API

This guide demonstrates how to integrate Magical Auth with your Node.js backend using the Glide SDK.

1

Install Dependencies

Install the Glide SDK for Node.js in your project.

The SDK handles communication with Glide's authentication servers and provides type-safe methods.

2

Initialize the SDK

Configure the Glide SDK with your API credentials.

Store your API key securely in environment variables.

  • Never commit API keys to version control
  • Use environment-specific configurations
  • The SDK handles retries and error recovery
3

Create Express Middleware

Set up Express middleware to handle phone authentication requests from your frontend.

This middleware:

  • Receives requests from your frontend SDK
  • Validates input data
  • Communicates with Glide servers
  • Returns responses to the frontend
4

Complete Express Server

Here's a complete Express server with phone authentication.

This example includes:

  • CORS configuration for frontend communication
  • Request validation and sanitization
  • Error handling middleware
  • Security best practices
5

Using Raw API (Without SDK)

If you prefer to use the raw API without the SDK, here's how to make direct HTTP calls.

This approach gives you:

  • Full control over HTTP client configuration
  • Ability to use any HTTP library (axios, fetch, got)
  • Custom retry and error handling logic
Terminal
npm install glide-sdk

# Or using yarn
yarn add glide-sdk

# Or using pnpm
pnpm add glide-sdk