import type { Auth, Session, User } from "better-auth"; import type { AuthResult } from "./client.js"; /** What `auth.api.getSession()` resolves to when a session exists. */ export interface AuthSessionData { user: User; session: Session; /** Plugins append their own fields (organization, roles, …). */ [key: string]: unknown; } /** The shape `Astro.locals` (or any framework's request context) ends up with. */ export interface AuthLocals { user: User | null; session: Session | null; } /** Anything that carries request headers: a `Request`, `Headers` or `{ headers }`. */ export type HeadersLike = Headers | Request | { headers: Headers; }; /** * Reads the current session server-side without throwing. * * Returns `data: null` with `ok: true` for an anonymous visitor — only a real * failure (bad config, network, malformed response) turns into `ok: false`. * * @param auth - The `betterAuth()` server instance * @param request - A `Request`, its `Headers`, or any object exposing `headers` * @returns Safe result with the session (or `null`) * * @example * ```ts * const session = await useAuthSession(auth, request); * if (session.ok && session.data) console.log(session.data.user.email); * ``` */ export declare function useAuthSession(auth: Auth, request: HeadersLike): Promise>; /** * Runs Better Auth's request handler (`auth.handler`) for a catch-all route. * * @param auth - The `betterAuth()` server instance * @param request - The incoming `Request` * @returns Safe result with the handler's `Response` * * @example Astro — `src/pages/api/auth/[...all].ts` * ```ts * import type { APIRoute } from "astro"; * import { auth } from "~/auth"; * import { useAuthHandler } from "katanakit-js/adapters/better-auth"; * * export const ALL: APIRoute = async ({ request }) => { * const result = await useAuthHandler(auth, request); * return result.ok ? result.data : new Response("Auth unavailable", { status: 500 }); * }; * ``` */ export declare function useAuthHandler(auth: Auth, request: Request): Promise>; /** * Builds the `user` / `session` pair middleware puts into the request context. * * Mirrors Better Auth's Astro middleware: anonymous visitors get `null` for * both fields instead of an error, so a page can branch on `locals.user`. * * @param auth - The `betterAuth()` server instance * @param request - The incoming `Request` (or anything carrying its headers) * @returns Safe result with `{ user, session }` * * @example Astro — `src/middleware.ts` * ```ts * import { defineMiddleware } from "astro:middleware"; * import { auth } from "~/auth"; * import { useAstroAuthLocals } from "katanakit-js/adapters/better-auth"; * * export const onRequest = defineMiddleware(async (context, next) => { * const locals = await useAstroAuthLocals(auth, context.request); * if (locals.ok) { * context.locals.user = locals.data.user; * context.locals.session = locals.data.session; * } * return next(); * }); * ``` */ export declare function useAstroAuthLocals(auth: Auth, request: HeadersLike): Promise>; //# sourceMappingURL=better-auth.service.d.ts.map