@zpg6-test-pkgs/better-auth
Version:
The most comprehensive authentication library for TypeScript.
1,061 lines (1,059 loc) • 1.16 MB
text/typescript
import * as nanostores from 'nanostores';
import * as _better_fetch_fetch from '@better-fetch/fetch';
import { SuccessContext } from '@better-fetch/fetch';
import { C as ClientOptions, B as BetterAuthClientPlugin, I as IsSignal, d as InferRoute, c as InferErrorCodes } from '../shared/better-auth.ueSiK_dg.cjs';
import { B as BetterAuthOptions, U as User, u as InferAPI, a as Adapter, v as AdditionalSessionFieldsOutput, p as Auth, w as AdditionalUserFieldsOutput, x as InferFieldsFromPlugins, y as InferFieldsFromOptions, z as AdditionalUserFieldsInput, i as BetterAuthPlugin, q as AuthContext, D as InferPluginTypes, j as InferPluginErrorCodes, F as FilterActions, S as Session, E as setCookieToHeader } from '../shared/better-auth.8Ira7TFx.cjs';
import * as better_call from 'better-call';
import { U as UnionToIntersection, S as StripEmptyObjects, a as Prettify } from '../shared/better-auth.DTtXpZYr.cjs';
import * as zod_v4_core from 'zod/v4/core';
import { O as OAuth2Tokens, a as OAuth2UserInfo } from '../shared/better-auth.DtuOgks-.cjs';
import * as zod from 'zod';
import { Kysely } from 'kysely';
import 'zod/v4';
import 'better-sqlite3';
import 'bun:sqlite';
import 'jose';
declare function getTestInstanceMemory<O extends Partial<BetterAuthOptions>, C extends ClientOptions>(options?: O, config?: {
clientOptions?: C;
port?: number;
disableTestUser?: boolean;
testUser?: Partial<User>;
testWith?: "sqlite" | "postgres" | "mongodb" | "mysql" | "memory";
}): Promise<{
auth: {
handler: (request: Request) => Promise<Response>;
api: InferAPI<{
ok: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: {
ok: boolean;
};
} : {
ok: boolean;
}>;
options: {
method: "GET";
metadata: {
openapi: {
description: string;
responses: {
"200": {
description: string;
content: {
"application/json": {
schema: {
type: "object";
properties: {
ok: {
type: string;
description: string;
};
};
required: string[];
};
};
};
};
};
};
isAction: false;
};
} & {
use: any[];
};
path: "/ok";
};
error: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: Response;
} : Response>;
options: {
method: "GET";
metadata: {
openapi: {
description: string;
responses: {
"200": {
description: string;
content: {
"text/html": {
schema: {
type: "string";
description: string;
};
};
};
};
};
};
isAction: false;
};
} & {
use: any[];
};
path: "/error";
};
signInSocial: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
body: {
provider: unknown;
callbackURL?: string | undefined;
newUserCallbackURL?: string | undefined;
errorCallbackURL?: string | undefined;
disableRedirect?: boolean | undefined;
idToken?: {
token: string;
nonce?: string | undefined;
accessToken?: string | undefined;
refreshToken?: string | undefined;
expiresAt?: number | undefined;
} | undefined;
scopes?: string[] | undefined;
requestSignUp?: boolean | undefined;
loginHint?: string | undefined;
};
} & {
method?: "POST" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: {
redirect: boolean;
token: string;
url: undefined;
user: {
id: string;
email: string;
name: string;
image: string | null | undefined;
emailVerified: boolean;
createdAt: Date;
updatedAt: Date;
};
} | {
url: string;
redirect: boolean;
};
} : {
redirect: boolean;
token: string;
url: undefined;
user: {
id: string;
email: string;
name: string;
image: string | null | undefined;
emailVerified: boolean;
createdAt: Date;
updatedAt: Date;
};
} | {
url: string;
redirect: boolean;
}>;
options: {
method: "POST";
body: zod.ZodObject<{
callbackURL: zod.ZodOptional<zod.ZodString>;
newUserCallbackURL: zod.ZodOptional<zod.ZodString>;
errorCallbackURL: zod.ZodOptional<zod.ZodString>;
provider: zod.ZodType<"github" | "apple" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "notion" | "line" | "paypal" | (string & {}), unknown, zod_v4_core.$ZodTypeInternals<"github" | "apple" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "notion" | "line" | "paypal" | (string & {}), unknown>>;
disableRedirect: zod.ZodOptional<zod.ZodBoolean>;
idToken: zod.ZodOptional<zod.ZodObject<{
token: zod.ZodString;
nonce: zod.ZodOptional<zod.ZodString>;
accessToken: zod.ZodOptional<zod.ZodString>;
refreshToken: zod.ZodOptional<zod.ZodString>;
expiresAt: zod.ZodOptional<zod.ZodNumber>;
}, zod_v4_core.$strip>>;
scopes: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
requestSignUp: zod.ZodOptional<zod.ZodBoolean>;
loginHint: zod.ZodOptional<zod.ZodString>;
}, zod_v4_core.$strip>;
metadata: {
openapi: {
description: string;
operationId: string;
responses: {
"200": {
description: string;
content: {
"application/json": {
schema: {
type: "object";
description: string;
properties: {
redirect: {
type: string;
enum: boolean[];
};
token: {
type: string;
description: string;
url: {
type: string;
nullable: boolean;
};
user: {
type: string;
properties: {
id: {
type: string;
};
email: {
type: string;
};
name: {
type: string;
nullable: boolean;
};
image: {
type: string;
nullable: boolean;
};
emailVerified: {
type: string;
};
createdAt: {
type: string;
format: string;
};
updatedAt: {
type: string;
format: string;
};
};
required: string[];
};
};
};
required: string[];
};
};
};
};
};
};
};
} & {
use: any[];
};
path: "/sign-in/social";
};
callbackOAuth: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
body?: {
code?: string | undefined;
error?: string | undefined;
device_id?: string | undefined;
error_description?: string | undefined;
state?: string | undefined;
user?: string | undefined;
} | undefined;
} & {
method: "GET" | "POST";
} & {
query?: {
code?: string | undefined;
error?: string | undefined;
device_id?: string | undefined;
error_description?: string | undefined;
state?: string | undefined;
user?: string | undefined;
} | undefined;
} & {
params: {
id: string;
};
} & {
request?: Request;
} & {
headers?: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: void;
} : void>;
options: {
method: ("GET" | "POST")[];
body: zod.ZodOptional<zod.ZodObject<{
code: zod.ZodOptional<zod.ZodString>;
error: zod.ZodOptional<zod.ZodString>;
device_id: zod.ZodOptional<zod.ZodString>;
error_description: zod.ZodOptional<zod.ZodString>;
state: zod.ZodOptional<zod.ZodString>;
user: zod.ZodOptional<zod.ZodString>;
}, zod_v4_core.$strip>>;
query: zod.ZodOptional<zod.ZodObject<{
code: zod.ZodOptional<zod.ZodString>;
error: zod.ZodOptional<zod.ZodString>;
device_id: zod.ZodOptional<zod.ZodString>;
error_description: zod.ZodOptional<zod.ZodString>;
state: zod.ZodOptional<zod.ZodString>;
user: zod.ZodOptional<zod.ZodString>;
}, zod_v4_core.$strip>>;
metadata: {
isAction: false;
};
} & {
use: any[];
};
path: "/callback/:id";
};
getSession: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
body?: undefined;
} & {
method?: "GET" | undefined;
} & {
query?: {
disableCookieCache?: unknown;
disableRefresh?: unknown;
} | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: {
session: UnionToIntersection<StripEmptyObjects<{
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
} & ((O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) extends infer T ? T extends (O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) ? T extends BetterAuthOptions ? AdditionalSessionFieldsOutput<T> : T extends Auth ? AdditionalSessionFieldsOutput<T["options"]> : {} : never : never)>>;
user: UnionToIntersection<StripEmptyObjects<{
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
} & ((O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) extends infer T_1 ? T_1 extends (O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) ? T_1 extends BetterAuthOptions ? AdditionalUserFieldsOutput<T_1> : T_1 extends Auth ? AdditionalUserFieldsOutput<T_1["options"]> : {} : never : never)>>;
} | null;
} : {
session: UnionToIntersection<StripEmptyObjects<{
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
} & ((O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) extends infer T_2 ? T_2 extends (O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) ? T_2 extends BetterAuthOptions ? AdditionalSessionFieldsOutput<T_2> : T_2 extends Auth ? AdditionalSessionFieldsOutput<T_2["options"]> : {} : never : never)>>;
user: UnionToIntersection<StripEmptyObjects<{
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image?: string | null | undefined;
} & ((O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) extends infer T_3 ? T_3 extends (O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}) ? T_3 extends BetterAuthOptions ? AdditionalUserFieldsOutput<T_3> : T_3 extends Auth ? AdditionalUserFieldsOutput<T_3["options"]> : {} : never : never)>>;
} | null>;
options: {
method: "GET";
query: zod.ZodOptional<zod.ZodObject<{
disableCookieCache: zod.ZodOptional<zod.ZodCoercedBoolean<unknown>>;
disableRefresh: zod.ZodOptional<zod.ZodCoercedBoolean<unknown>>;
}, zod_v4_core.$strip>>;
requireHeaders: true;
metadata: {
openapi: {
description: string;
responses: {
"200": {
description: string;
content: {
"application/json": {
schema: {
type: "object";
properties: {
session: {
$ref: string;
};
user: {
$ref: string;
};
};
required: string[];
};
};
};
};
};
};
};
} & {
use: any[];
};
path: "/get-session";
};
signOut: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0: {
body?: undefined;
} & {
method?: "POST" | undefined;
} & {
query?: Record<string, any> | undefined;
} & {
params?: Record<string, any>;
} & {
request?: Request;
} & {
headers: HeadersInit;
} & {
asResponse?: boolean;
returnHeaders?: boolean;
use?: better_call.Middleware[];
path?: string;
} & {
asResponse?: AsResponse | undefined;
returnHeaders?: ReturnHeaders | undefined;
}): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
headers: Headers;
response: {
success: boolean;
};
} : {
success: boolean;
}>;
options: {
method: "POST";
requireHeaders: true;
metadata: {
openapi: {
description: string;
responses: {
"200": {
description: string;
content: {
"application/json": {
schema: {
type: "object";
properties: {
success: {
type: string;
};
};
};
};
};
};
};
};
};
} & {
use: any[];
};
path: "/sign-out";
};
signUpEmail: {
<AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(...inputCtx: better_call.HasRequiredKeys<better_call.InputContext<"/sign-up/email", {
method: "POST";
body: zod.ZodRecord<zod.ZodString, zod.ZodAny>;
metadata: {
$Infer: {
body: {
name: string;
email: string;
password: string;
image?: string;
callbackURL?: string;
rememberMe?: boolean;
} & InferFieldsFromPlugins<O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
} : O & {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};
secret: string;
database: ((options: BetterAuthOptions) => Adapter) | {
db: Kysely<unknown>;
type: "postgres";
} | {
db: Kysely<unknown>;
type: "mysql";
} | undefined;
emailAndPassword: {
enabled: true;
};
rateLimit: {
enabled: false;
};
advanced: {
cookies: {};
};
}, "user", "input"> & InferFieldsFromOptions<O extends undefined ? {
socialProviders: {
github: {
clientId: string;
clientSecret: string;
};
google: {
clientId: string;
clientSecret: string;
};
};