Step 3 – Add an Off-Chain Identity Layer (Magmar Auth)

Magmar Smart Accounts are wallet-agnostic, so we need a conventional method to map a real-world user to an on-chain account before we can mint NFTs on their behalf. For this tutorial we’ll use Userbase, a quick, server-less identity service to keep things simple. Remember: this is fine for demos, not for production.

3.1 Install and Configure Userbase

  1. Install the SDK

npm i userbase-js
  1. Create a Userbase project

  • Visit https://userbase.com and sign up

  • After login, you’ll see a default Starter App → copy its App ID

  1. Add environment variables

# .env.local
NEXT_PUBLIC_USERBASE_APP_ID=<YOUR_APP_ID>

NEXT_PUBLIC_ exposes the value to the browser—required by the SDK.

  1. Generate an access token

  • In the dashboard, open Account → Access Tokens

  • Label it magmar-get-user and click Generate

Add the token to .env.local:

USERBASE_ACCESS_TOKEN=<YOUR_ACCESS_TOKEN>

3.2 Create an AuthProvider

Inside /common, add AuthProvider.tsx:


3.3 Wrap the App with AuthProvider

Modify app/layout.tsx (Next 13 App Router):

We restrict chains to Sepolia to keep testnet usage safe.


3.4 Result

Any component can now call useAuth() to read or update the current user:

You’ve connected an off-chain identity system to Magmar Smart Accounts. Next we’ll create Sign-Up and Login routes that:

  1. Generate a private key for the user

  2. Derive their deterministic smart-contract wallet address

  3. Store both in Userbase (plaintext only for demo!)

Last updated