Core SDK
Core types and utilities for the Groo Auth SDK.
Installation
npm install @groo.dev/auth-core
note
This package is automatically included when you install @groo.dev/auth-react or @groo.dev/auth-server. You typically don't need to install it directly.
Overview
auth-core provides TypeScript types and the AuthClient class used by both the React and server packages. It ensures type consistency across your frontend and backend.
When to Use Directly
You might import from auth-core directly when:
- You need type definitions without the full React or server package
- You're building custom integrations
- You need the
AuthClientfor custom authentication flows
Types
User
interface User {
id: string
email: string | null
phone: string | null
name: string | null
role: string
}
ConsentedUser
User object with consent information (returned from session validation):
interface ConsentedUser extends User {
consent: {
id: string
userId: string
applicationId: string
consentedAt: string
lastAccessedAt: string
revokedAt: string | null
appData: Record<string, unknown>
}
}
AuthConfig
Configuration for initializing the auth client:
interface AuthConfig {
clientId: string
clientSecret?: string // Required for server-side
baseUrl?: string // Default: 'https://accounts.groo.dev'
cookieName?: string // Default: 'session'
}
UseAuthReturn
Return type from the useAuth hook:
interface UseAuthReturn {
user: User | null
isLoading: boolean
error: Error | null
loginUrl: string
logoutUrl: string
refetch: () => Promise<void>
}
AuthClient
The core authentication client for making requests to the accounts service.
Constructor
import { AuthClient } from '@groo.dev/auth-core'
const client = new AuthClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret', // Optional for client-side
baseUrl: 'https://accounts.groo.dev',
})
Methods
validateSession
Validate a session cookie and return the user:
const user = await client.validateSession(sessionCookie)
// Returns: ConsentedUser | null
getLoginUrl
Generate a login URL:
const url = client.getLoginUrl(redirectUri)
// Returns: string
getLogoutUrl
Generate a logout URL:
const url = client.getLogoutUrl(redirectUri)
// Returns: string
Exports
// Types
export type { User, ConsentedUser, AuthConfig, UseAuthReturn }
// Client
export { AuthClient }