Skip to main content
Templates and example integrations help you move faster and avoid rework. Use these as starting points for your integration.

Starter Templates

All templates are available in the examples directory.

bun-react

SSO authentication and activity tracking with Bun server and React frontend. This example shows the SDK handlers (/api/timeback/*) plus a simple UI. For an example that also demonstrates the direct API escape hatch (timeback.api), see examples/bun-react-full.

Quick Start

Structure

Key Patterns

Native handler — Mount Timeback routes:
SignInButton — Pre-styled SSO button:
Activity tracking — Track learning time:

bun-react-full

SSO authentication and activity tracking with Bun server and React frontend. This “full” variant also includes a small demo of direct API access via timeback.api (an escape hatch for calling Timeback services like OneRoster).

Quick Start

Structure

Key Patterns

Native handler — Mount Timeback routes:
SignInButton — Pre-styled SSO button:
Activity tracking — Track learning time:

bun-react-gradeless

SSO authentication and activity tracking for grade-less apps (e.g., CS platforms). This example demonstrates using courseCode instead of (subject, grade) for course identity.

Quick Start

Grade-less Course Configuration

Apps without grade levels use courseCode as the course identifier:

Activity Tracking with courseCode

When evaluating examples, it’s often useful to preview what would be sent without actually sending Caliper events. This example uses:
  • normal activity.end(...) (production-like)
  • a server-side hook (beforeActivitySend) to optionally skip sending and log what would be sent

Demo toggle

In .env:
Compare this to grade-based apps (see examples/bun-react):

Structure


bun-react-identity-only

SSO authentication with Bun server and React frontend — no activity tracking. This example demonstrates createTimebackIdentity() for apps that only need Timeback SSO without the full SDK.

Quick Start

Structure

Key Differences from Full SDK

  • Uses createTimebackIdentity() instead of createTimeback()
  • No api credentials required
  • No timeback.config.json required
  • Only identity routes are available (no activity tracking)

Key Patterns

Identity-only server — No API credentials needed:
SignInButton — Pre-styled SSO button:

bun-react-resumable

SSO authentication and activity tracking with Bun server and React frontend. This example shows the SDK handlers (/api/timeback/*) plus a simple UI. For an example that also demonstrates the direct API escape hatch (timeback.api), see examples/bun-react-full.

Quick Start

Structure

Key Patterns

Native handler — Mount Timeback routes:
SignInButton — Pre-styled SSO button:
Activity tracking — Track learning time:

express

Minimal Express.js backend demonstrating the Timeback SDK’s Express adapter.

Quick Start

Verify Routes

Run the verification script to test all routes:
This starts the server, tests all endpoints, and reports results.

Routes

Testing

Integration Options

The SDK provides two ways to integrate with Express:

Option 2: Router mounting


express-auth0

Demonstrates using the Timeback SDK with Auth0 as a custom identity provider. This example uses Auth0’s email/password authentication (Resource Owner Password Grant) with the official auth0 Node.js SDK.

Architecture

Auth0 Setup

  1. Create an Auth0 Application
    • Go to Auth0 Dashboard → Applications → Create Application
    • Choose “Regular Web Application”
    • Note your Domain, Client ID, and Client Secret
  2. Enable Password Grant
    • In your application settings, go to Advanced SettingsGrant Types
    • Enable Password grant type
  3. Create a Database Connection (if you don’t have one)
    • Go to Authentication → Database → Create Connection
    • Enable it for your application
  4. Create Test Users
    • Go to User Management → Users → Create User
    • Create users with email/password

Quick Start

Environment Variables

Create .env from .env.example:

How It Works

1. User Login

User submits email/password → Backend calls Auth0’s password grant → Auth0 validates → Returns user info → Backend creates signed JWT session cookie.

2. Session Management

The session cookie contains { sub, email, name } signed with HS256. It’s httpOnly, secure in production, and lasts 7 days.

3. Timeback Integration

The SDK calls getEmail(req) on each request. We parse the cookie header, verify the JWT, and return the user’s email. The SDK then resolves the Timeback user by email.

4. Frontend Activity Tracking

Project Structure

API Routes

Troubleshooting

”Invalid email or password”

  • Verify the user exists in Auth0 (User Management → Users)
  • Check that the Password grant type is enabled
  • Ensure the database connection is enabled for your app

”Auth0 is not configured”

  • Check AUTH0_DOMAIN, AUTH0_CLIENT_ID, AUTH0_CLIENT_SECRET in .env
  • Domain should be just your-tenant.auth0.com (no https://)

Session not persisting

  • Check browser dev tools → Application → Cookies
  • In development, cookies work on localhost
  • The Vite proxy ensures same-origin for cookie handling

CORS errors

  • The Vite dev server proxies /auth and /api to the backend
  • No CORS configuration needed in development

express-auth0-launch-gate

Activity tracking demo using Auth0 Universal Login (SPA + PKCE) in the frontend and Bearer-token auth in the backend, with a launch-gated entry URL (/timeback/signin).

Architecture

How It Works

  1. Auth0 handles authentication - Frontend uses Auth0 Universal Login (Authorization Code + PKCE)
  2. Frontend calls backend with Bearer token - API requests include Authorization: Bearer {'<'}access_token{'>'}
  3. Backend validates token - using Auth0 JWKS + issuer + audience
  4. SDK uses custom identity mode - The getEmail callback reads email from the request
  5. SDK resolves Timeback user - When submitting activity, SDK looks up the Timeback user by email
This pattern is ideal when:
  • You have an existing Auth0 SPA
  • Your backend is a resource server (Bearer JWT auth)
  • You want a dedicated Timeback launch URL (/timeback/signin) without a separate “Sign in with Timeback” button

Quick Start

1. Auth0 Setup

  1. Create an API in Auth0 (Applications → APIs) and copy its Identifier (this is the audience)
  2. Create a Single Page Application in Auth0 (Applications → Applications)
  3. In the SPA settings, set:
    • Allowed Callback URLs: http://localhost:5173
    • Allowed Logout URLs: http://localhost:5173
    • Allowed Web Origins: http://localhost:5173
  4. Ensure the Database connection is enabled for the SPA (email/password hosted by Auth0)

2. Environment Setup

Edit .env with your credentials.

3. Install and Run

Open http://localhost:5173

Launch-gated URL

Visit http://localhost:5173/timeback/signin to simulate the Timeback launch URL.

Commands

API Endpoints

Auth Endpoints

This example uses Auth0 Universal Login (SPA + PKCE), so there are no backend /auth/* routes. The backend behaves like a typical resource server: it only validates Authorization: Bearer {'<'}access_token{'>'}.

Timeback SDK Endpoints

Session Endpoints

Project Structure


express-supabase

Demonstrates using the Timeback SDK with Supabase as a custom identity provider.

Architecture

Setup

1. Install dependencies

2. Configure environment

Edit .env with your credentials:
  • Supabase: Get URL and Publishable key from Supabase Dashboard > Settings > API
  • Timeback: Get from Timeback Dashboard

3. Create a Supabase user

In your Supabase Dashboard:
  1. Go to Authentication > Users
  2. Click “Add user” > “Create new user”
  3. Enter email and password

4. Start development servers

Timeback Integration

The SDK is configured with custom identity mode, reading the user’s email from the session cookie:

Available Commands


nextjs-app-router

SSO authentication and activity tracking with Next.js App Router.

Quick Start

Structure

Key Patterns

API routes — Handle auth routes via toNextjsHandler:
SignInButton — Pre-styled SSO button:
Activity tracking — Track learning time:

nuxt

Look at the Nuxt documentation to learn more.

Setup

Make sure to install dependencies:

Development Server

Start the development server on http://localhost:3000:

Production

Build the application for production:
Locally preview production build:
Check out the deployment documentation for more information.

qti-with-powerpath

Demonstrates real PowerPath API integration for adaptive learning and standard quizzes. This example calls the actual PowerPath API - no local simulation. The app only:
  1. Renders questions from PowerPath
  2. Submits answers to PowerPath
  3. Displays results from PowerPath

Quick Start

Open http://localhost:5174 to take a quiz.

Two Quiz Types

Both use the same PowerPath API endpoints - the lessonType determines behavior.

What is PowerPath 100?

PowerPath 100 refers to the powerpath-100 lesson type that uses PowerPath’s adaptive algorithm. The “100” comes from the goal: reaching a PowerPath score of 100. How the algorithm works:
  • Score starts at 0 and the goal is to reach 100
  • Question difficulty is selected based on current score:
    • 0-49: Easy questions
    • 50-89: Medium + Hard mix (75%/25%)
    • 90-99: Hard questions only
  • Correct answers increase your score; incorrect answers decrease it
  • 80% PP score is the passing threshold (but the quiz continues until 100 or questions exhausted)
The PP score is weighted - harder questions have more impact. A student with 100% accuracy sees ~11 questions; 80% accuracy sees ~18 questions.

Architecture

The app does NOT implement any quiz logic. PowerPath handles:
  • Which question to show next
  • Difficulty adaptation (for PowerPath 100)
  • Scoring and pass/fail determination
  • Attempt tracking

Project Structure

API Endpoints

Quiz Flow

Attempt History

Configuration

Example: Quiz Flow

Environment Variables

Features

Attempt History

Users can review past completed attempts:
  • View all previous attempts with scores
  • Navigate through each question
  • See which answers were correct/incorrect
  • Compare PP score vs raw accuracy

Time Tracking

Time tracking uses the Timeback client SDK in time-only mode:
  • The client starts an activity at quiz start and calls activity.end({}) on completion
  • The server handler emits a TimeSpentEvent (no ActivityCompletedEvent)
  • Results show a “Time tracked” indicator
  • Idle detection: When the user switches tabs or minimizes the window, the activity is automatically paused via activity.pause() and resumed via activity.resume() on return, so idle time is excluded from the tracked duration
This is separate from PowerPath’s grading - it’s for learning analytics only.

Key Points

  1. No local algorithm - PowerPath handles all quiz logic
  2. Real API calls - Every action goes through PowerPath
  3. Two lesson types - Same code, different behavior based on lessonType
  4. Setup required - Must run bun run setup before the app works
  5. PP score ≠ accuracy - PowerPath 100 uses weighted scoring, not raw percent correct

solid-start

SolidStart app with Timeback SSO authentication and activity tracking.

Quick Start

File Structure

Key Patterns

Server SDKtoSolidStartHandler(timeback) in API routes ClientSignInButton, Activity from timeback/solid Session → Server-side store, fetched via /api/session

svelte-kit

SSO authentication and activity tracking with SvelteKit.

Quick Start

Structure

Key Patterns

Server hooks — Handle auth routes via svelteKitHandler:
SignInButton — Pre-styled SSO button:
Activity tracking — Track learning time:

tanstack-start

SSO authentication and activity tracking with TanStack Start.

Quick Start

File Structure

Key Patterns

Server config — Configure SSO in src/lib/timeback.ts:
API routes — Mount Timeback handlers:
Client — Use the React adapter:

Next Steps

Quickstart

Get started with integration

SDK Overview

Learn about SDK features

Configuration

Full config reference

Developer Program

Apply for access