A minimal prototype demonstrating passwordless authentication via magic links using SuperTokens, Node.js, and Docker.
https://github.com/davidbmar/supertokens_nodejs · public · shipped
This project is a reference implementation of passwordless authentication. It replaces traditional passwords with time-limited, single-use magic links sent to the user's email. The system consists of a static HTML frontend for inputting emails and verifying tokens, an Express.js backend handling session management and SuperTokens integration, and a SuperTokens Core instance running in Docker with PostgreSQL for persistent storage.
docker-compose up -d npm start npx serve -s .
flowchart TD
User[User Browser] -->|HTTP Request| Frontend[Static Frontend :3000]
Frontend -->|API Call| Backend[Node.js/Express Server :3001]
Backend -->|Auth Logic| ST_SDK[supertokens-node SDK]
ST_SDK -->|HTTP API| Core[SuperTokens Core :3567]
Core -->|Read/Write| DB[(PostgreSQL :5432)]
Backend -->|Log Link| Console[Server Console]
The backend uses the `supertokens-node` SDK with Express middleware to handle auth routes. The SuperTokens Core (v9.3.0) runs in a Docker container alongside PostgreSQL. The frontend is a static site served via `npx serve`, interacting with the backend API. Magic links are logged to the server console instead of being sent via SMTP for demonstration purposes.
sequenceDiagram
participant U as User
participant F as Frontend (:3000)
participant B as Backend (:3001)
participant S as SuperTokens Core
participant D as PostgreSQL
U->>F: Enter Email & Click Send
F->>B: POST /auth/signinup/code
B->>S: Create Code (Email)
S->>D: Store Code & Hash
S-->>B: Return PreAuthSessionID
B-->>F: Success Response
B->>B: Log Magic Link to Console
U->>U: Copy Link from Console
U->>F: Open Magic Link
F->>B: GET /auth/signinup/code/consume
B->>S: Consume Code
S->>D: Validate & Delete Code
S-->>B: Return Session Tokens
B-->>F: Set Session Cookie & Redirect
F->>U: Show Dashboard
Use this as a starting point for integrating passwordless login into Node.js applications. Replace the console-based email delivery with a real SMTP provider (e.g., SendGrid, AWS SES) by modifying the `emailDelivery` override in `server.js`. Customize `appInfo.js` with your production domains.
✓ all on main — nothing unmerged.