Getting Started
Set up authentication in your React application.
Installation
npm install @groo.dev/auth-react
Setup AuthProvider
Wrap your app with AuthProvider:
import { AuthProvider } from '@groo.dev/auth-react'
function App() {
return (
<AuthProvider
baseUrl="http://localhost:8787"
clientId="your-client-id"
redirectUri="http://localhost:3000"
>
<YourApp />
</AuthProvider>
)
}
Configuration Options
| Prop | Type | Required | Description |
|---|---|---|---|
baseUrl | string | Yes | Your API's base URL (not accounts service) |
clientId | string | Yes | Your application's client ID |
redirectUri | string | Yes | Where to redirect after auth |
Important
The baseUrl should point to your own API, not the accounts service. The AuthProvider calls GET /v1/__auth/me on your API.
Next.js Setup
For Next.js, create a client component for the provider:
// app/providers.tsx
'use client'
import { AuthProvider } from '@groo.dev/auth-react'
export function Providers({ children }: { children: React.ReactNode }) {
return (
<AuthProvider
baseUrl={process.env.NEXT_PUBLIC_BASE_URL!}
clientId={process.env.NEXT_PUBLIC_CLIENT_ID!}
redirectUri={process.env.NEXT_PUBLIC_REDIRECT_URI!}
>
{children}
</AuthProvider>
)
}
Then wrap your app in layout.tsx:
// app/layout.tsx
import { Providers } from './providers'
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
)
}
Environment Variables
# .env
NEXT_PUBLIC_BASE_URL=http://localhost:8787
NEXT_PUBLIC_CLIENT_ID=your-client-id
NEXT_PUBLIC_REDIRECT_URI=http://localhost:3000
How It Works
The AuthProvider:
- Calls
GET /v1/__auth/meon your API - Your API validates the session cookie and returns the user
- Provides authentication state to all child components
- Generates login/logout URLs with correct parameters