Skip to main content

Overview

The user profile contains an enriched view of the current user, including identity information, school, grade, enrolled courses, goals, and XP totals. You can access user data in several ways:
  1. Server-side: verify users or fetch profiles directly from your backend
  2. Client-side: use a framework hook with built-in state and caching

Server-Side

The timeback.user namespace provides programmatic methods that accept an email directly. Use them in your own API routes, server actions, webhooks, cron jobs, or any backend context.

Verify a user

Use timeback.user.verify(email) to check whether a Timeback user exists for a given email. This is a lightweight check — it does not fetch enrollments, analytics, or build an enriched profile.
const result = await timeback.user.verify('student@example.com')

if (result.verified) {
	console.log(result.timebackId) // "tb_abc123"
}
Useful for gating features (e.g., offering a free tier to Timeback users) without the cost of a full profile fetch.
verified
boolean
Whether the user exists in Timeback.
timebackId
string
The Timeback user ID. Only present when verified is true.

Get a user profile

Use timeback.user.getProfile(email) to get the full enriched profile — identity, enrollments, courses, goals, and XP. This is the programmatic equivalent of the /user/me HTTP handler.
const email = 'student@example.com'
const profile = await timeback.user.getProfile(email)
Throws a TimebackUserResolutionError if the user cannot be resolved. If you’re not sure whether a user exists, call verify() first.

Client-Side

On the client, use the framework-specific profile hook. The hook handles loading state, caching, and session-aware refetching — you never call timeback.user.fetch() directly from the browser.
import { useTimebackProfile } from '@timeback/sdk/react'

// Manual fetch
function ProfileButton() {
	const { state, canFetch, fetchProfile } = useTimebackProfile()

	if (state.status === 'loaded') {
		return <div>XP: {state.profile.xp.today}</div>
	}

	return (
		<button onClick={fetchProfile} disabled={!canFetch}>
			{state.status === 'loading' ? 'Loading...' : 'Load Profile'}
		</button>
	)
}

// Auto-fetch when verified
function AutoProfile() {
	const { state } = useTimebackProfile({ auto: true })

	if (state.status === 'loading') return <div>Loading...</div>
	if (state.status === 'loaded') return <div>XP: {state.profile.xp.today}</div>

	return null
}

Hook State

The profile hook returns a state object with these statuses:
StatusDescription
idleInitial state, no fetch attempted
loadingFetch in progress
loadedProfile successfully loaded
errorFetch failed

Caching

The client SDK caches profile data to minimize API calls:
  • Profile is fetched once per session
  • Manual refetch available via fetchProfile()
  • Cache is invalidated on sign-out

Next Steps

Custom Activities

Track activities to earn XP

Identity

Authentication setup

EduBridge Client

Advanced analytics queries

OneRoster Client

Query enrollments directly