---
title: "Build an AI Wellbeing App with Fireworks and Fitbit via Auth0 Token Vault."
description: "Daily Wellbeing is a Next.js 16 and TypeScript app that reads Fitbit activity, sleep, and resting heart-rate data through the Google Health API v4 and uses Fireworks to suggest general wellbeing actions. Auth0 handles sign-in, while Token Vault stores the Fitbit authorization credentials and lets the server retrieve a token for the signed-in user. The app calculates a daily report for the latest completed day, compares it with recent averages, and keeps missing values marked as unknown. Users can review those readings without running inference and must explicitly choose to share the summary before Fireworks is called. The /api/advice route requires a valid session and an exact matching origin, rejects client-supplied readings or prompts, forces the summary tool on the first model step, then streams suggestions with tools disabled and thinking turned off."
---

# Build an AI Wellbeing App with Fireworks and Fitbit via Auth0 Token Vault.

[Auth0](https://yomu.fyi/company/auth0) · Deepu K Sasidharan · Nov 2, 2026

**Type:** Tutorial

## Summary

Daily Wellbeing is a Next.js 16 and TypeScript app that reads Fitbit activity, sleep, and resting heart-rate data through the Google Health API v4 and uses Fireworks to suggest general wellbeing actions. Auth0 handles sign-in, while Token Vault stores the Fitbit authorization credentials and lets the server retrieve a token for the signed-in user. The app calculates a daily report for the latest completed day, compares it with recent averages, and keeps missing values marked as unknown. Users can review those readings without running inference and must explicitly choose to share the summary before Fireworks is called. The /api/advice route requires a valid session and an exact matching origin, rejects client-supplied readings or prompts, forces the summary tool on the first model step, then streams suggestions with tools disabled and thinking turned off.

## Context

The app targets personal Google accounts with a linked health profile; Google Workspace accounts cannot own the health profile. Fitbit readings are exposed through Google Health API v4, requiring Google Cloud OAuth credentials and a custom Auth0 OAuth2 connection. A new health account may have no readings, so users need synced data or a sleep log before generating suggestions. Expired authorization and rate limits produce errors with reconnect or retry controls.

## Approach / What changed

The sample uses Auth0 Next.js SDK 4 for login, Connected Accounts, and Token Vault; AI SDK 7 with @ai-sdk/fireworks; and Zod validation. The server retrieves the user’s Fitbit token through Token Vault, builds a normalized daily report, and exposes it through getDailyFitbitSummary. The /api/advice route validates the session, origin, and a body containing only shareWithFireworks: true, fetches the report before streaming, forces the tool on step one, disables tools on step two, sets maxOutputTokens to 1,536, disables Fireworks thinking, and streams Markdown rendered without raw HTML or remote images.

## Takeaways

- Token Vault stores the Fitbit authorization credentials, and the server retrieves a token for the signed-in user; the Fireworks key stays on the backend and Google OAuth credentials stay in Auth0.
- The /api/advice route accepts only {“shareWithFireworks”: true}, rejects extra fields such as client-supplied readings, prompts, account identifiers, and tokens, and requires a valid session plus an exact matching request origin.
- The summary tool returns normalized dates, timezone, measurements, comparison counts, and data warnings, while excluding Fitbit names, profile identifiers, weight, activity descriptions, sleep stages, and log IDs.

## FAQ

### How does the app prevent the model from receiving data before the user consents?

The /api/advice route requires the body {"shareWithFireworks": true} and rejects extra fields, including client-supplied readings, prompts, account identifiers, and tokens. The server fetches the report before starting the stream, and the model receives it through the getDailyFitbitSummary tool only after that sharing choice.

### What happens on the first and second model steps?

prepareStep forces getDailyFitbitSummary on step zero, so the tool returns the current user's fetched report. On the second step, toolChoice is set to none and stopWhen stepCountIs(2) ends the run after the suggestions are produced.

### What data does the summary tool omit?

Its output excludes Fitbit names, profile identifiers, weight, activity descriptions, sleep stages, and log IDs. It includes normalized dates, timezone, measurements, comparison counts, and constructed data warnings.

**Tags:** [Auth0](https://yomu.fyi/topic/auth0), [Fireworks](https://yomu.fyi/topic/fireworks), [Fitbit](https://yomu.fyi/topic/fitbit), [Next.js](https://yomu.fyi/topic/next-js), [Token Vault](https://yomu.fyi/topic/token-vault)

- Source: [Auth0](https://auth0.com/blog/build-an-ai-wellbeing-app-with-fireworks-fitbit-via-auth0-token-vault)
- Source URL: https://auth0.com/blog/build-an-ai-wellbeing-app-with-fireworks-fitbit-via-auth0-token-vault
- Ingested by Yomu: 2026-11-03T00:00:13.759Z

[Read original post](https://auth0.com/blog/build-an-ai-wellbeing-app-with-fireworks-fitbit-via-auth0-token-vault)
