Three React context providers wrap the entire application insideDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Jason-AML/MonzaSport-Nextjs/llms.txt
Use this file to discover all available pages before exploring further.
src/app/layout.js: I18nProvider (translations), QueryProvider (TanStack React Query), and AuthProvider (Supabase session). They compose from the outside in — each inner provider can safely consume the context of any provider that wraps it, making the dependency order deliberate and important.
Provider Stack
The root layout is anasync Server Component that fetches the current user before rendering. The resolved user object is threaded down as a prop to AuthProvider, eliminating any client-side loading flash:
src/app/layout.js
I18nProvideris outermost so that every component in the tree — including login forms, the navbar, and error pages — has translation strings available from the very first render.QueryProvidersits in the middle, making the sharedQueryClientinstance available to any client component that callsuseQueryoruseMutation, including those insideAuthProvider.AuthProvideris innermost so it can leverage React Query if needed for session-aware data fetching, while still being wrapped by translations for any auth-related UI text.
Navbar, Footer, and FloatingBar are placed inside AuthProvider so they can call useAuth() to conditionally render user-specific UI — such as a profile dropdown when the user is signed in.AuthProvider
File:src/providers/AuthProvider.jsx
AuthProvider manages the Supabase session for the entire application. It is a 'use client' component that accepts the server-resolved user as initialUser, then subscribes to supabase.auth.onAuthStateChange to keep the local state in sync with any subsequent sign-in or sign-out events.
How it works
Server-side prefetch
getUser() runs in the Server Component root layout via @/lib/server. The resolved user (or null) is passed as initialUser to AuthProvider before the page is sent to the browser — no client-side loading state is needed on first paint.State initialisation
useState(initialUser) seeds the auth state immediately. If initialUser is non-null, loading starts as false, so components never see an intermediate “loading” flash.Realtime subscription
useEffect calls supabase.auth.onAuthStateChange, which fires whenever the session changes (sign-in, sign-out, token refresh). The callback updates user and sets loading to false.Source
src/providers/AuthProvider.jsx
Consuming the context
QueryProvider
File:src/providers/QueryProvider.jsx
QueryProvider wraps the app with QueryClientProvider from TanStack React Query v5. It creates a single shared QueryClient instance (via useState to prevent re-creation on re-renders) and mounts the React Query Devtools in development.
Configuration
src/providers/QueryProvider.jsx
| Default Option | Value | Effect |
|---|---|---|
staleTime | 60 000 ms | Cached vehicle data is considered fresh for one minute before a background refetch is triggered |
refetchOnWindowFocus | false | Switching browser tabs does not trigger a refetch, avoiding unnecessary Supabase reads |
I18nProvider
File:src/providers/I18nProvider.jsx
I18nProvider initializes i18next and exposes the configured instance to every component via I18nextProvider. Because i18next initialization is a side-effect that must run in the browser, the provider is marked 'use client' and imports @/i18n/index to trigger the setup.
Initialization
src/i18n/index.js
Provider component
src/providers/I18nProvider.jsx
Translation key namespaces
Translations are organized by feature in bothen.js and es.js:
| Namespace key | Used by |
|---|---|
nav | Navbar — navigation links and register button |
floatingBar | FloatingBar — help text and concierge CTA |
profile_dropdown | Navbar — authenticated user menu |
home_hero | HeroVideo — headline, tagline, CTA buttons |
login | LoginForm — labels, placeholders, links |
register | RegisterForm — labels, validation toasts |
categorie_split | CategorySplit — cars and bikes section copy |
testimonials | Testimonials — review text and roles |
latest_news | LatestNews — article titles and tags |
footer | Footer — links, newsletter, legal text |
Consuming translations in a component
The root
<html> element in layout.js has lang="es" set statically. If you extend the app with full locale-aware routing, update this attribute dynamically based on the active i18next language.Supabase Clients
Two Supabase client factories live insrc/lib/ and serve distinct rendering environments. Both export a function named createClient, so the correct file must always be imported explicitly.
src/lib/client.ts — Browser client
src/lib/client.ts
'use client' component or custom hook. It reads the public environment variables and creates a session-aware client backed by browser storage.
src/lib/server.ts — Server client
src/lib/server.ts
src/services/auth/auth.server.js. It reads and writes cookies via the Next.js cookies() API, allowing the server to access and refresh the user’s Supabase session.
Quick reference
| Import path | Environment | Used in |
|---|---|---|
@/lib/client | Browser | AuthProvider, useChat, collectionClient.js, auth.client.js |
@/lib/server | Server | auth.server.js, collections.js, API route handlers |