better-auth
Version:
The most comprehensive authentication framework for TypeScript.
1 lines • 3.27 kB
Source Map (JSON)
{"version":3,"file":"vanilla.mjs","names":["resolvedHooks: Record<string, any>"],"sources":["../../src/client/vanilla.ts"],"sourcesContent":["import type {\n\tBetterAuthClientOptions,\n\tBetterAuthClientPlugin,\n} from \"@better-auth/core\";\nimport type { BASE_ERROR_CODES } from \"@better-auth/core/error\";\nimport { capitalizeFirstLetter } from \"@better-auth/core/utils\";\nimport type {\n\tBetterFetchError,\n\tBetterFetchResponse,\n} from \"@better-fetch/fetch\";\nimport type { Atom } from \"nanostores\";\nimport type { PrettifyDeep, UnionToIntersection } from \"../types/helper\";\nimport { getClientConfig } from \"./config\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport type {\n\tInferActions,\n\tInferClientAPI,\n\tInferErrorCodes,\n\tIsSignal,\n} from \"./types\";\n\ntype InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {\n\tplugins: Array<infer Plugin>;\n}\n\t? UnionToIntersection<\n\t\t\tPlugin extends BetterAuthClientPlugin\n\t\t\t\t? Plugin[\"getAtoms\"] extends (fetch: any) => infer Atoms\n\t\t\t\t\t? Atoms extends Record<string, any>\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t[key in keyof Atoms as IsSignal<key> extends true\n\t\t\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t\t\t: key extends string\n\t\t\t\t\t\t\t\t\t\t? `use${Capitalize<key>}`\n\t\t\t\t\t\t\t\t\t\t: never]: Atoms[key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}\n\t\t\t\t\t: {}\n\t\t\t\t: {}\n\t\t>\n\t: {};\n\nexport function createAuthClient<Option extends BetterAuthClientOptions>(\n\toptions?: Option | undefined,\n) {\n\tconst {\n\t\tpluginPathMethods,\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\t$fetch,\n\t\tatomListeners,\n\t\t$store,\n\t} = getClientConfig(options);\n\tlet resolvedHooks: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(pluginsAtoms)) {\n\t\tresolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;\n\t}\n\tconst routes = {\n\t\t...pluginsActions,\n\t\t...resolvedHooks,\n\t\t$fetch,\n\t\t$store,\n\t};\n\tconst proxy = createDynamicPathProxy(\n\t\troutes,\n\t\t$fetch,\n\t\tpluginPathMethods,\n\t\tpluginsAtoms,\n\t\tatomListeners,\n\t);\n\ttype ClientAPI = InferClientAPI<Option>;\n\ttype Session = ClientAPI extends {\n\t\tgetSession: () => Promise<infer Res>;\n\t}\n\t\t? Res extends BetterFetchResponse<infer S>\n\t\t\t? S\n\t\t\t: Res extends Record<string, any>\n\t\t\t\t? Res\n\t\t\t\t: never\n\t\t: never;\n\treturn proxy as UnionToIntersection<InferResolvedHooks<Option>> &\n\t\tClientAPI &\n\t\tInferActions<Option> & {\n\t\t\tuseSession: Atom<{\n\t\t\t\tdata: Session;\n\t\t\t\terror: BetterFetchError | null;\n\t\t\t\tisPending: boolean;\n\t\t\t}>;\n\t\t\t$fetch: typeof $fetch;\n\t\t\t$store: typeof $store;\n\t\t\t$Infer: {\n\t\t\t\tSession: NonNullable<Session>;\n\t\t\t};\n\t\t\t$ERROR_CODES: PrettifyDeep<\n\t\t\t\tInferErrorCodes<Option> & typeof BASE_ERROR_CODES\n\t\t\t>;\n\t\t};\n}\n\nexport type AuthClient<Option extends BetterAuthClientOptions> = ReturnType<\n\ttypeof createAuthClient<Option>\n>;\n"],"mappings":";;;;;AAyCA,SAAgB,iBACf,SACC;CACD,MAAM,EACL,mBACA,gBACA,cACA,QACA,eACA,WACG,gBAAgB,QAAQ;CAC5B,IAAIA,gBAAqC,EAAE;AAC3C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,aAAa,CACtD,eAAc,MAAM,sBAAsB,IAAI,MAAM;AAyBrD,QAjBc,uBANC;EACd,GAAG;EACH,GAAG;EACH;EACA;EACA,EAGA,QACA,mBACA,cACA,cACA"}