Note: The iframe-based email authentication pattern used in this example is no longer supported with the latest
@turnkey/react-wallet-kitSDK package.Recommended alternatives:
- Email OTP Authentication - Authenticate users with one-time passcodes sent via email
- Magic Link Authentication - Authenticate users with magic links sent via email
This example shows a complete email auth flow. It contains a NextJS app with:
- a frontend application
- a backend application
The overall flow for email auth is outlined below:

This example contains an example auth page as well as a stub API endpoint for "your business" (where the email is resolved into an organization ID). The creation of the hidden iframe is abstracted by our @turnkey/iframe-stamper package. For more information on email auth, check out our documentation.
Make sure you have node installed locally; we recommend using Node v18+.
$ git clone https://github.com/tkhq/sdk
$ cd sdk/
$ corepack enable # Install `pnpm`
$ pnpm install -r # Install dependencies
$ pnpm run build-all # Compile source code
$ cd examples/email-auth/The first step is to set up your Turnkey organization and account. By following the Quickstart guide, you should have:
- A public/private API key pair for Turnkey
- An organization ID
Once you've gathered these values, add them to a new .env.local file. Notice that your API private key should be securely managed and never be committed to git.
$ cp .env.local.example .env.localNow open .env.local and add the missing environment variables:
API_PUBLIC_KEYAPI_PRIVATE_KEYNEXT_PUBLIC_ORGANIZATION_IDNEXT_PUBLIC_BASE_URL(theNEXT_PUBLICprefix makes the env variable accessible to the frontend app)NEXT_PUBLIC_AUTH_IFRAME_URL
$ pnpm run devThis command will run a NextJS app on port 3000. If you navigate to http://localhost:3000 in your browser, you can follow the prompts to start an email auth.
