UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

47 lines (43 loc) 1.38 kB
import { type QueryOptions, skipToken } from "@tanstack/query-core" import { authQueryKeys } from "../../lib/auth-query-keys" import type { AgentApproval, AgentApprovalRequest, AgentAuthAdapter, AgentAuthorization } from "./agent-auth-adapter" export const agentAuthQueryKeys = { all: (userId?: string) => [...authQueryKeys.user(userId), "agent-auth"] as const, approval: (request?: AgentApprovalRequest, userId?: string) => [ ...agentAuthQueryKeys.all(userId), "approval", request?.agentId, request?.approvalId, request?.userCode ] as const, agents: (userId?: string) => [...agentAuthQueryKeys.all(userId), "agents"] as const } as const export const agentApprovalOptions = ( adapter: AgentAuthAdapter, request: AgentApprovalRequest | undefined, userId?: string ) => ({ queryKey: agentAuthQueryKeys.approval(request, userId), meta: { errorPresentation: "inline" }, queryFn: request && userId ? ({ signal }) => adapter.getApproval(request, signal) : skipToken }) satisfies QueryOptions<AgentApproval> export const agentAuthorizationsOptions = ( adapter: AgentAuthAdapter, userId?: string ) => ({ queryKey: agentAuthQueryKeys.agents(userId), queryFn: userId ? ({ signal }) => adapter.listAgents(signal) : skipToken }) satisfies QueryOptions<AgentAuthorization[]>