Skip to main content
Version: Node.js

Your First Verification

This guide will help you get started with the Magical Auth API by going through the steps to perform your first 2FA verification.

Prerequisites

Before you begin, you need to have the following:

Step 1: Get your API Credentials

To get your API Credentials, you can go to the Magical Auth Product Page and click on "Manage on Provider" to access the service dashboard. For a full guide on how to get your credentials, you can refer to the Registration guide.

Step 2: Create a new project

Create a new folder and enter the folder from a terminal.

mkdir magical-auth-test
cd magical-auth-test

Step 3: Initialize the SDK

npm init -y
npm install glide-sdk

Step 4: Perform a Verification

index.ts
import { GlideClient } from "glide-sdk";

const PHONE_NUMBER = "+555123456789"

async function main() {
const glide = new GlideClient({
"clientId": <GLIDE_CLIENT_ID>,
"clientSecret": <GLIDE_CLIENT_SECRET>
});
const magicAuthStartResponse = await glide.magicAuth.startAuth({
phoneNumber: PHONE_NUMBER
});

const token = await fetch(magicAuthStartResponse.authUrl);

const magicAuthCheckResponse = await glide.magicAuth.verifyAuth({
phoneNumber: PHONE_NUMBER,
token: token.headers.get("token") as string
});
console.log('magic auth response', magicAuthCheckResponse);
}

main().catch(console.error);
NOTE

Since we are using the test number +555123456789, the verification will always return type MAGIC and provide an authUrl. Unlike a regular MAGIC verification where the link would need to be opened on the user's device, this test number will return a test URL that can be opened on any device.

Because of this we can simply fetch the URL and extract the token from the response headers directly from the script.

With a token received, you can then verify the user's phone number using the verifyAuth method.

Using the test number you should get back a response saying the verification was successful.

To run the script, you can use the following command:

npx tsx index.ts

Conclusion

You have successfully performed your first verification using the Magical Auth API. You can now follow our 5-minute quickstart to deploying a test application using the Magical Auth API.