Add user invitation functionality using Turalogin V2. This allows admins to invite users via email with a custom message. V2 invites include both a magic link AND a 6-digit code fallback.
How it works:
1. Admin enters the user's email and a custom welcome message
2. Your backend calls Turalogin's V2 invite API
3. Turalogin sends a branded invite email with the admin's message, a clickable link, AND a 6-digit code
4. User clicks the link or enters the code. Both paths verify the invite.
5. Your backend verifies with Turalogin (server-side only) and gets back a JWT + any metadata
6. User is now authenticated and onboarded
API Details:
- Base URL: https://www.turalogin.com/api/v2
- IMPORTANT: Every API request MUST include the Authorization header:
Authorization: Bearer <TURALOGIN_API_KEY>
Security Notes:
- The /auth/verify/* endpoints MUST be called server-side only (never from browser)
- Your TURALOGIN_API_KEY must never be exposed to the client
Environment Variables:
- TURALOGIN_API_KEY: Your API key from the dashboard
- APP_REDIRECT_URL: The URL where invite links redirect to
- Development: http://localhost:3000/auth/verify
- Production: https://myapp.com/auth/verify
Example fetch call:
fetch('https://www.turalogin.com/api/v2/auth/invite', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TURALOGIN_API_KEY}`
},
body: JSON.stringify({
email: 'newuser@example.com',
message: 'Welcome to our team! Click below to get started.',
redirectUrl: process.env.APP_REDIRECT_URL,
appName: 'My App',
expiresIn: 86400,
metadata: { role: 'member', teamId: 'team-123' }
})
})
Endpoints:
POST /api/v2/auth/invite
Body: { email, message, redirectUrl, method?, expiresIn?, appName?, metadata?, cc?, bcc? }
- email: The user's email address to invite
- message: Custom message from admin (max 500 chars, shown in invite email)
- redirectUrl: The URL where the invite link redirects (required for ota method)
- method: "ota" (link + code, default) or "otp" (code only)
- expiresIn: Seconds until expiry (60-604800, default 86400 = 24 hours)
- appName: Override app name in email (max 128 chars)
- metadata: JSON object (max 4KB) returned on verification
- cc: Array of email addresses to receive a notification copy (max 5, no auth link/code included)
- bcc: Array of email addresses to receive a hidden notification copy (max 5, no auth link/code included)
Returns: { success, token, method, message, expiresAt }
Verification (same endpoints as login):
POST /api/v2/auth/verify/link - Body: { token } → Returns: { success, jwt, user: { email }, metadata? }
POST /api/v2/auth/verify/code - Body: { token, code } → Returns: { success, jwt, user: { email }, metadata? }
Invite Status:
GET /api/v2/auth/invite/{token}/status → Returns: { status, email, createdAt, expiresAt, usedAt }
- status: "pending" | "used" | "expired"
Batch Invites:
POST /api/v2/auth/invite/batch - Body: { invites: [{ email, message }], redirectUrl, appName?, expiresIn?, metadata?, cc?, bcc? }
Returns: { success, sent, failed, results: [{ email, token?, success, error? }] }
Error Responses:
- 400: Missing or invalid parameters
- 401: Invalid, expired, or already-used token
- 500: Server error (retry with exponential backoff)
Session Constraints:
- Invite links expire after 24 hours by default (customizable up to 7 days)
- Each link/code can only be used once (single-use)
- After verification, create your own session - Turalogin does not manage sessions
- metadata from the invite is returned in the verification response
Please create:
1. Admin invite form with email input and message textarea
2. API endpoint to send invites (calls Turalogin /api/v2/auth/invite)
3. Handle both verification paths: link click (/verify/link) and code entry (/verify/code)
4. Show success/error states after sending invite
5. Optionally use metadata to pass role/team context through the invite flow
6. Optionally check invite status via GET /api/v2/auth/invite/{token}/status