import { InsforgeUser } from '@insforge/shared'; /** * Session information extracted from cookies */ interface InsforgeAuth { /** * The current user's ID, or null if not authenticated */ userId: string | null; /** * The current session token, or null if not authenticated */ token: string | null; /** * User information (email, name) if available */ user: InsforgeUser | null; } /** * Get authentication information from cookies in Server Components, * Route Handlers, and Server Actions. * * This function reads the HTTP-only cookies set by the middleware * and returns user authentication data. * * @example * ```ts * // In a Server Component * import { auth } from '@insforge/nextjs/server'; * * export default async function Page() { * const { userId, token } = await auth(); * * if (!userId) { * return
Not authenticated
; * } * * return
User ID: {userId}
; * } * ``` * * @example * ```ts * // In an API Route Handler * import { auth } from '@insforge/nextjs/server'; * import { createClient } from '@insforge/sdk'; * * export async function GET() { * const { userId, token } = await auth(); * * if (!userId || !token) { * return Response.json({ error: 'Unauthorized' }, { status: 401 }); * } * * // Use token with SDK * const insforge = createClient({ * baseUrl: process.env.INSFORGE_BASE_URL!, * edgeFunctionToken: token, * }); * * const result = await insforge.database.from('posts').select(); * return Response.json(result.data); * } * ``` * * @example * ```ts * // In a Server Action * 'use server'; * * import { auth } from '@insforge/nextjs/server'; * * export async function createPost(formData: FormData) { * const { userId } = await auth(); * * if (!userId) { * throw new Error('Not authenticated'); * } * * // Create post with userId * } * ``` */ declare function auth(): Promise; export { type InsforgeAuth, auth };