import Link from 'next/link'; import { cookies } from 'next/headers'; type CurrentUser = { id: string; email: string; email_verified: boolean }; type Vehicle = { id: string; nickname: string; make: string; model: string; year?: number | null }; type Ride = { id: string; started_at: string; distance_miles?: number | null; top_speed_mph?: number | null; status: string }; type Subscription = { plan: string; status: string }; async function loadAccount(): Promise<{ user: CurrentUser; vehicles: Vehicle[]; rides: Ride[]; subscription: Subscription } | null> { const token = (await cookies()).get('motorsignal_access_token')?.value; if (!token) return null; const baseUrl = process.env.MOTORSIGNAL_API_BASE_URL ?? 'https://api.motorsignal.app'; try { const response = await fetch(`${baseUrl}/api/v1/me`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }); if (!response.ok) return null; const user = await response.json() as CurrentUser; const [vehiclesResponse, ridesResponse, subscriptionResponse] = await Promise.all([ fetch(`${baseUrl}/api/v1/vehicles`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }), fetch(`${baseUrl}/api/v1/rides?page=1&page_size=5`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }), fetch(`${baseUrl}/api/v1/me/subscription`, { headers: { authorization: `Bearer ${token}` }, cache: 'no-store' }), ]); return { user, vehicles: vehiclesResponse.ok ? await vehiclesResponse.json() as Vehicle[] : [], rides: ridesResponse.ok ? (await ridesResponse.json()).items as Ride[] : [], subscription: subscriptionResponse.ok ? await subscriptionResponse.json() as Subscription : { plan: 'free', status: 'unknown' } }; } catch { return null; } } export default async function AccountPage() { const account = await loadAccount(); if (!account) return
Account portal

Sign in to your rider space.

Manage your MotorSignal account, security, vehicles, and ride history from one place.

Sign inCreate account
; return
Account portal

Welcome back.

{account.user.email}

Profile

Account status: Active

Email verification: {account.user.email_verified ? 'Verified' : 'Pending'}

Plan

{account.subscription.plan} · {account.subscription.status}

Vehicles

{account.vehicles.length ? account.vehicles.map((vehicle) =>

{vehicle.nickname} · {vehicle.year ?? ''} {vehicle.make} {vehicle.model}

) :

No vehicles yet.

}

Recent rides

{account.rides.length ? account.rides.map((ride) =>

{new Date(ride.started_at).toLocaleDateString()} · {ride.distance_miles ?? 0} mi · {ride.status}

) :

No rides yet.

}
; }