Sign In with Email/Phone Number

Our JavaScript SDK offers the easiest way to integrate Cotter 's email/phone verification. You can simply embed Cotter's Login Form and it will do the heavy lifting for you.

Concepts: Learn about how Sign in with Email/Phone Number works.

What you're building

Cotter's Embeddable Login Form using the JS SDK

Try it out

Quickly try out how it works in our Hello World Example! πŸŽ‰

Overview

Verifying email and phone number in your website using our JavaScript SDK consists of the following steps:

  1. Embed Cotter in your website

  2. Receive a Callback with user's data and a token from Cotter

  3. Send the token to your backend server

Steps

  1. Setup Cotter with your API_KEY_ID and some config

  2. Send the Payload containing the user's information to your backend server

Step 1: Setup Cotter

Include Javascript SDK

To use our Javascript SDK, include the script below in your HTML page or use the npm package.

Make sure you check for the latest version at https://www.npmjs.com/package/cotter

Initialize Cotter

Initialize Cotter in your Login page. If using HTML, put this script at the bottom of your <body> . If you're using React, put this in useEffect or componentDidMount . We want this script to run right after the page is loaded.

Adding more fields

You can also add more fields, customize the styles, and intercept the authentication request before it's sent. Check out how to Customize the Form.

Send Code via WhatsApp

Instead of using SMS, you can also send the code via WhatsApp. Go to the Dashboard > Branding and chose "Phone" on top of the preview.

To send code/link via SMS or WhatsApp, you'll need to add some balance to you project in the Dashboard.

Step 2: Show Cotter Form

Add the <div> container with id "cotter-form-container"

What we have so far

Step 3: Sending the Payload to your Backend Server

You can get the authentication response in the then callback function and send it to your server. For example:

The payload that you receive from the promise is a JSON Object with the following format:

You should verify the access token to ensure this is valid and it comes from Cotter's server.

Handling the response in your backend

Backend: Handling Response

πŸŽ‰ You're done!

Securing your Project

Since you'll be using your API Key from a front-end website or mobile app, your API_KEY_ID is exposed to anyone inspecting your code. Here are some ways to prevent abuse:

What's Next

Last updated