ApiKeyID: "<your-API-KEY-ID>",
// Type of identity your want to collect: EMAIL or PHONE
// div id of the container for Cotter Form
ContainerID: "cotter-container-login",
// the JSON key for the phone number or email to be posted to RedirectURL
// Read more on RedirectURL JSON Object below
IdentifierField: "phone",
// OnBegin here is MANDATORY
// You need to return the Cotter User ID. (If you used client_user_id,
OnBegin: async payload => {
var { userID, err } = await getUserIDFromIdentifier(
// After the user successfully logged-in, the SDK will return a payload
// about the login request into this OnSuccess function.
// (optional) Allow login using OTP sent to email or phone number
// if user doesn't have Trusted Device set up
// or if user choose to use OTP instead of trusted device
// (To enable this, you have to set OTP true in the dashboard)
// Getting the User ID usnig Cotter's API
const getUserIDFromIdentifier = async (identifier) => {
const resp = await fetch(
`https://www.cotter.app/api/v0/user?identifier=${encodeURIComponent(
{ headers: { API_KEY_ID: apiKey } }
const respJSON = await resp.json();
const nullUUID = "00000000-0000-0000-0000-000000000000";
userID: respJSON.ID === nullUUID ? null : respJSON.client_user_id,
err: respJSON.ID === nullUUID ? "User not found" : null