better-auth 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +805 -2
- package/dist/cli.js.map +1 -1
- package/dist/client.js +1 -4
- package/dist/client.js.map +1 -1
- package/dist/index.js +806 -6
- package/dist/index.js.map +1 -1
- package/dist/plugins.js +1 -4
- package/dist/plugins.js.map +1 -1
- package/dist/preact.js +1 -4
- package/dist/preact.js.map +1 -1
- package/dist/react.js +1 -4
- package/dist/react.js.map +1 -1
- package/dist/social.js +1 -4
- package/dist/social.js.map +1 -1
- package/dist/solid.js +1 -4
- package/dist/solid.js.map +1 -1
- package/dist/svelte.js +1 -4
- package/dist/svelte.js.map +1 -1
- package/dist/vue.js +1 -4
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/preact.js
CHANGED
|
@@ -39,10 +39,7 @@ function getBaseURL(url, path) {
|
|
|
39
39
|
if (url) {
|
|
40
40
|
return withPath(url, path);
|
|
41
41
|
}
|
|
42
|
-
const env = typeof process !== "undefined" ? process.env :
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
import.meta.env
|
|
45
|
-
) : {};
|
|
42
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
46
43
|
const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
47
44
|
if (fromEnv) {
|
|
48
45
|
return withPath(fromEnv, path);
|
package/dist/preact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/preact.ts","../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts"],"sourcesContent":["import { useStore } from \"@nanostores/react\";\nexport const useAuthStore = useStore;\n\nimport type { BetterFetchOption } from \"@better-fetch/fetch\";\nimport { createAuthClient as createVanillaClient } from \"./base\";\n\nexport const createAuthClient = (options?: BetterFetchOption) => {\n\tconst client = createVanillaClient(options);\n\treturn Object.assign(client);\n};\n","import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;A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B;AAAA,QACnB,GAAG;AAAA,QACH,GAAG,GAAG;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU;AAAA,IACf,QAAQ;AAAA,MACP;AAAA,IACD;AAAA,IACA;AAAA,IACA,GAAI;AAAA,IACJ,GAAG;AAAA,EACJ;AAIA,QAAM,QAAQ;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,MACC,GAAG;AAAA,MACH,aAAa;AAAA,IACd;AAAA,IACA;AAAA,MACC;AAAA,QACC,SAAS,CAAC,SAAS,SAAS;AAAA,QAC5B,MAAM;AAAA,MACP;AAAA,MACA;AAAA,QACC,SAAS,CAAC,SAAS,KAAK,WAAW,eAAe;AAAA,QAClD,MAAM;AAAA,MACP;AAAA,MACA;AAAA,QACC,SAAS,CAAC,SACT,SAAS,eACT,KAAK,WAAW,UAAU,KAC1B,KAAK,WAAW,UAAU;AAAA,QAC3B,MAAM;AAAA,MACP;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,IACA;AAAA,MACC;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD;AACA,SAAO;AACR;;;AD1JO,IAAM,eAAe;AAKrB,IAAMA,oBAAmB,CAAC,YAAgC;AAChE,QAAM,SAAS,iBAAoB,OAAO;AAC1C,SAAO,OAAO,OAAO,MAAM;AAC5B;","names":["createAuthClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/preact.ts","../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts"],"sourcesContent":["import { useStore } from \"@nanostores/react\";\nexport const useAuthStore = useStore;\n\nimport type { BetterFetchOption } from \"@better-fetch/fetch\";\nimport { createAuthClient as createVanillaClient } from \"./base\";\n\nexport const createAuthClient = (options?: BetterFetchOption) => {\n\tconst client = createVanillaClient(options);\n\treturn Object.assign(client);\n};\n","import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,SAAS,IAAI,IAAI,GAAG,EAAE;AAAA,MACtB,UAAU;AAAA,IACX;AAAA,EACD;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO;AAAA,IACN,SAAS;AAAA,IACT,UAAU,GAAG,GAAG,GAAG,IAAI;AAAA,EACxB;AACD;AAEO,SAAS,WAAW,KAAc,MAAe;AACvD,MAAI,KAAK;AACR,WAAO,SAAS,KAAK,IAAI;AAAA,EAC1B;AACA,QAAM,MAAW,OAAO,YAAY,cAAc,QAAQ,MAAM,CAAC;AACjE,QAAM,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,eAAe;AAAA,QAClD,MAAM;AAAA,MACP;AAAA,MACA;AAAA,QACC,SAAS,CAAC,SACT,SAAS,eACT,KAAK,WAAW,UAAU,KAC1B,KAAK,WAAW,UAAU;AAAA,QAC3B,MAAM;AAAA,MACP;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,IACA;AAAA,MACC;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD;AACA,SAAO;AACR;;;AD1JO,IAAM,eAAe;AAKrB,IAAMA,oBAAmB,CAAC,YAAgC;AAChE,QAAM,SAAS,iBAAoB,OAAO;AAC1C,SAAO,OAAO,OAAO,MAAM;AAC5B;","names":["createAuthClient"]}
|
package/dist/react.js
CHANGED
|
@@ -39,10 +39,7 @@ function getBaseURL(url, path) {
|
|
|
39
39
|
if (url) {
|
|
40
40
|
return withPath(url, path);
|
|
41
41
|
}
|
|
42
|
-
const env = typeof process !== "undefined" ? process.env :
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
import.meta.env
|
|
45
|
-
) : {};
|
|
42
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
46
43
|
const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
47
44
|
if (fromEnv) {
|
|
48
45
|
return withPath(fromEnv, path);
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/react.ts","../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts"],"sourcesContent":["import { useStore } from \"@nanostores/react\";\nimport {\n\tcreateAuthFetch,\n\tcreateAuthClient as createVanillaClient,\n} from \"./base\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\nexport const createAuthClient = <Option extends ClientOptions>(\n\toptions?: Option,\n) => {\n\tconst $fetch = createAuthFetch(options);\n\tconst hooks = options?.authPlugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...(plugin($fetch).integrations?.react?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as Option[\"authPlugins\"] extends Array<infer Pl>\n\t\t? Pl extends AuthPlugin\n\t\t\t? UnionToIntersection<\n\t\t\t\t\tReturnType<Pl>[\"integrations\"] extends\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\treact?: (useStore: any) => infer R;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? R\n\t\t\t\t\t\t: {}\n\t\t\t\t>\n\t\t\t: {}\n\t\t: {};\n\n\tconst client = createVanillaClient(options, hooks);\n\n\tfunction useSession(\n\t\tinitialValue: typeof client.$atoms.$session.value = null,\n\t) {\n\t\tconst session = useStore(client.$atoms.$session);\n\t\tif (session) {\n\t\t\treturn session;\n\t\t}\n\t\treturn initialValue;\n\t}\n\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n\nexport const useAuthStore = useStore;\n","import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,SAAS,IAAI,IAAI,GAAG,EAAE;AAAA,MACtB,UAAU;AAAA,IACX;AAAA,EACD;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO;AAAA,IACN,SAAS;AAAA,IACT,UAAU,GAAG,GAAG,GAAG,IAAI;AAAA,EACxB;AACD;AAEO,SAAS,WAAW,KAAc,MAAe;AACvD,MAAI,KAAK;AACR,WAAO,SAAS,KAAK,IAAI;AAAA,EAC1B;AAEA,QAAM,MACL,OAAO,YAAY,cAChB,QAAQ,MACR,OAAO,gBAAgB;AAAA;AAAA,IAEvB,YAAY;AAAA,MACX,CAAC;AACN,QAAM,UACL,IAAI,mBACJ,IAAI,YACJ,IAAI,wBACJ,IAAI,+BACJ,IAAI,mBACJ,IAAI,0BACJ,IAAI,+BACJ,IAAI;AACL,MAAI,SAAS;AACZ,WAAO,SAAS,SAAS,IAAI;AAAA,EAC9B;AAEA,QAAM,QACL,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A,IACJ;AAAA,IACA;AAAA,MACC;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD;AACA,SAAO;AACR;;;ADnJO,IAAMA,oBAAmB,CAC/B,YACI;AACJ,QAAM,SAAS,gBAAgB,OAAO;AACtC,QAAM,QAAQ,SAAS,aAAa;AAAA,IACnC,CAAC,KAAK,WAAW;AAChB,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAI,OAAO,MAAM,EAAE,cAAc,QAAQ,QAAQ,KAAK,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAcA,QAAM,SAAS,iBAAoB,SAAS,KAAK;AAEjD,WAAS,WACR,eAAoD,MACnD;AACD,UAAM,UAAU,SAAS,OAAO,OAAO,QAAQ;AAC/C,QAAI,SAAS;AACZ,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAEO,IAAM,eAAe;","names":["createAuthClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/react.ts","../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts"],"sourcesContent":["import { useStore } from \"@nanostores/react\";\nimport {\n\tcreateAuthFetch,\n\tcreateAuthClient as createVanillaClient,\n} from \"./base\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\nexport const createAuthClient = <Option extends ClientOptions>(\n\toptions?: Option,\n) => {\n\tconst $fetch = createAuthFetch(options);\n\tconst hooks = options?.authPlugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...(plugin($fetch).integrations?.react?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as Option[\"authPlugins\"] extends Array<infer Pl>\n\t\t? Pl extends AuthPlugin\n\t\t\t? UnionToIntersection<\n\t\t\t\t\tReturnType<Pl>[\"integrations\"] extends\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\treact?: (useStore: any) => infer R;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? R\n\t\t\t\t\t\t: {}\n\t\t\t\t>\n\t\t\t: {}\n\t\t: {};\n\n\tconst client = createVanillaClient(options, hooks);\n\n\tfunction useSession(\n\t\tinitialValue: typeof client.$atoms.$session.value = null,\n\t) {\n\t\tconst session = useStore(client.$atoms.$session);\n\t\tif (session) {\n\t\t\treturn session;\n\t\t}\n\t\treturn initialValue;\n\t}\n\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n\nexport const useAuthStore = useStore;\n","import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;;;ACAzB,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aA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AAS;AACZ,aAAO;AAAA,IACR;AACA,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAEO,IAAM,eAAe;","names":["createAuthClient"]}
|
package/dist/social.js
CHANGED
|
@@ -38,10 +38,7 @@ function getBaseURL(url, path) {
|
|
|
38
38
|
if (url) {
|
|
39
39
|
return withPath(url, path);
|
|
40
40
|
}
|
|
41
|
-
const env = typeof process !== "undefined" ? process.env :
|
|
42
|
-
//@ts-ignore
|
|
43
|
-
import.meta.env
|
|
44
|
-
) : {};
|
|
41
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
45
42
|
const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
46
43
|
if (fromEnv) {
|
|
47
44
|
return withPath(fromEnv, path);
|
package/dist/social.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/social-providers/apple.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/social-providers/utils.ts","../src/social-providers/discord.ts","../src/social-providers/facebook.ts","../src/social-providers/github.ts","../src/social-providers/google.ts","../src/social-providers/spotify.ts","../src/social-providers/twitch.ts","../src/social-providers/twitter.ts","../src/types/provider.ts","../src/social-providers/index.ts"],"sourcesContent":["import { OAuth2Tokens } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { parseJWT } from \"oslo/jwt\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\nimport { getRedirectURI } from \"./utils\";\nexport interface AppleProfile {\n\t/**\n\t * The subject registered claim identifies the principal that’s the subject\n\t * of the identity token. Because this token is for your app, the value is\n\t * the unique identifier for the user.\n\t */\n\tsub: string;\n\t/**\n\t * A String value representing the user's email address.\n\t * The email address is either the user's real email address or the proxy\n\t * address, depending on their status private email relay service.\n\t */\n\temail: string;\n\t/**\n\t * A string or Boolean value that indicates whether the service verifies\n\t * the email. The value can either be a string (\"true\" or \"false\") or a\n\t * Boolean (true or false). The system may not verify email addresses for\n\t * Sign in with Apple at Work & School users, and this claim is \"false\" or\n\t * false for those users.\n\t */\n\temail_verified: true | \"true\";\n\t/**\n\t * A string or Boolean value that indicates whether the email that the user\n\t * shares is the proxy address. The value can either be a string (\"true\" or\n\t * \"false\") or a Boolean (true or false).\n\t */\n\tis_private_email: boolean;\n\t/**\n\t * An Integer value that indicates whether the user appears to be a real\n\t * person. Use the value of this claim to mitigate fraud. The possible\n\t * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For\n\t * more information, see ASUserDetectionStatus. This claim is present only\n\t * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14\n\t * and later. The claim isn’t present or supported for web-based apps.\n\t */\n\treal_user_status: number;\n\t/**\n\t * The user’s full name in the format provided during the authorization\n\t * process.\n\t */\n\tname: string;\n}\n\nexport interface AppleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const apple = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: AppleOptions) => {\n\tconst tokenEndpoint = \"https://appleid.apple.com/auth/token\";\n\tredirectURI = getRedirectURI(\"apple\", redirectURI);\n\treturn {\n\t\tid: \"apple\",\n\t\tname: \"Apple\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\", \"name\", \"openid\"];\n\t\t\treturn new URL(\n\t\t\t\t`https://appleid.apple.com/auth/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectURI}&scope=${_scope.join(\n\t\t\t\t\t\" \",\n\t\t\t\t)}&state=${state}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code) => {\n\t\t\tconst data = await betterFetch<OAuth2Tokens>(tokenEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t\tclient_secret: clientSecret,\n\t\t\t\t\tgrant_type: \"authorization_code\",\n\t\t\t\t\tcode,\n\t\t\t\t}),\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (data.error) {\n\t\t\t\tthrow new BetterAuthError(data.error?.message || \"\");\n\t\t\t}\n\t\t\treturn data.data;\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst data = parseJWT(token.idToken())?.payload as AppleProfile | null;\n\t\t\tif (!data) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: data.sub,\n\t\t\t\t\tname: data.name,\n\t\t\t\t\temail: data.email,\n\t\t\t\t\temailVerified: data.email_verified === \"true\",\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<AppleProfile>;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { getBaseURL } from \"../utils/base-url\";\n\nexport function getRedirectURI(providerId: string, redirectURI?: string) {\n\treturn redirectURI || `${getBaseURL()}/api/auth/callback/${providerId}`;\n}\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Discord } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface DiscordProfile extends Record<string, any> {\n\t/** the user's id (i.e. the numerical snowflake) */\n\tid: string;\n\t/** the user's username, not unique across the platform */\n\tusername: string;\n\t/** the user's Discord-tag */\n\tdiscriminator: string;\n\t/** the user's display name, if it is set */\n\tglobal_name: string | null;\n\t/**\n\t * the user's avatar hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tavatar: string | null;\n\t/** whether the user belongs to an OAuth2 application */\n\tbot?: boolean;\n\t/**\n\t * whether the user is an Official Discord System user (part of the urgent\n\t * message system)\n\t */\n\tsystem?: boolean;\n\t/** whether the user has two factor enabled on their account */\n\tmfa_enabled: boolean;\n\t/**\n\t * the user's banner hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tbanner: string | null;\n\n\t/** the user's banner color encoded as an integer representation of hexadecimal color code */\n\taccent_color: number | null;\n\n\t/**\n\t * the user's chosen language option:\n\t * https://discord.com/developers/docs/reference#locales\n\t */\n\tlocale: string;\n\t/** whether the email on this account has been verified */\n\tverified: boolean;\n\t/** the user's email */\n\temail: string;\n\t/**\n\t * the flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tflags: number;\n\t/**\n\t * the type of Nitro subscription on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-premium-types\n\t */\n\tpremium_type: number;\n\t/**\n\t * the public flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tpublic_flags: number;\n\t/** undocumented field; corresponds to the user's custom nickname */\n\tdisplay_name: string | null;\n\t/**\n\t * undocumented field; corresponds to the Discord feature where you can e.g.\n\t * put your avatar inside of an ice cube\n\t */\n\tavatar_decoration: string | null;\n\t/**\n\t * undocumented field; corresponds to the premium feature where you can\n\t * select a custom banner color\n\t */\n\tbanner_color: string | null;\n\t/** undocumented field; the CDN URL of their profile picture */\n\timage_url: string;\n}\n\nexport interface DiscordOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const discord = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: DiscordOptions) => {\n\tconst discordArctic = new Discord(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"discord\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"discord\",\n\t\tname: \"Discord\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\"];\n\t\t\treturn discordArctic.createAuthorizationURL(state, _scope);\n\t\t},\n\t\tvalidateAuthorizationCode: discordArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<DiscordProfile>(\n\t\t\t\t\"https://discord.com/api/users/@me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name || profile.username || \"\",\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<DiscordProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Facebook } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface FacebookProfile {\n\tid: string;\n\tname: string;\n\temail: string;\n\temail_verified: boolean;\n\tpicture: {\n\t\tdata: {\n\t\t\theight: number;\n\t\t\tis_silhouette: boolean;\n\t\t\turl: string;\n\t\t\twidth: number;\n\t\t};\n\t};\n}\nexport interface FacebookOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const facebook = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: FacebookOptions) => {\n\tconst facebookArctic = new Facebook(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"facebook\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"facebook\",\n\t\tname: \"Facebook\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"email\", \"public_profile\"];\n\t\t\treturn facebookArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: facebookArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<FacebookProfile>(\n\t\t\t\t\"https://graph.facebook.com/me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<FacebookProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { GitHub } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface GithubProfile {\n\tlogin: string;\n\tid: string;\n\tnode_id: string;\n\tavatar_url: string;\n\tgravatar_id: string;\n\turl: string;\n\thtml_url: string;\n\tfollowers_url: string;\n\tfollowing_url: string;\n\tgists_url: string;\n\tstarred_url: string;\n\tsubscriptions_url: string;\n\torganizations_url: string;\n\trepos_url: string;\n\tevents_url: string;\n\treceived_events_url: string;\n\ttype: string;\n\tsite_admin: boolean;\n\tname: string;\n\tcompany: string;\n\tblog: string;\n\tlocation: string;\n\temail: string;\n\thireable: boolean;\n\tbio: string;\n\ttwitter_username: string;\n\tpublic_repos: string;\n\tpublic_gists: string;\n\tfollowers: string;\n\tfollowing: string;\n\tcreated_at: string;\n\tupdated_at: string;\n\tprivate_gists: string;\n\ttotal_private_repos: string;\n\towned_private_repos: string;\n\tdisk_usage: string;\n\tcollaborators: string;\n\ttwo_factor_authentication: boolean;\n\tplan: {\n\t\tname: string;\n\t\tspace: string;\n\t\tprivate_repos: string;\n\t\tcollaborators: string;\n\t};\n\tfirst_name: string;\n\tlast_name: string;\n}\n\nexport interface GithubOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const github = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GithubOptions) => {\n\tconst githubArctic = new GitHub(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"github\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"github\",\n\t\tname: \"Github\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user:email\"];\n\t\t\treturn githubArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: githubArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<GithubProfile>(\n\t\t\t\t\"https://api.github.com/user\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet emailVerified = false;\n\t\t\tif (!profile.email) {\n\t\t\t\tconst { data, error } = await betterFetch<\n\t\t\t\t\t{\n\t\t\t\t\t\temail: string;\n\t\t\t\t\t\tprimary: boolean;\n\t\t\t\t\t\tverified: boolean;\n\t\t\t\t\t\tvisibility: \"public\" | \"private\";\n\t\t\t\t\t}[]\n\t\t\t\t>(\"https://api.github.com/user/emails\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t\t\"User-Agent\": \"better-auth\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (!error) {\n\t\t\t\t\tprofile.email = (data.find((e) => e.primary) ?? data[0])\n\t\t\t\t\t\t?.email as string;\n\t\t\t\t\temailVerified =\n\t\t\t\t\t\tdata.find((e) => e.email === profile.email)?.verified ?? false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.avatar_url,\n\t\t\t\t\temailVerified,\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GithubProfile>;\n};\n","import { Google } from \"arctic\";\nimport { parseJWT } from \"oslo/jwt\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface GoogleProfile {\n\taud: string;\n\tazp: string;\n\temail: string;\n\temail_verified: boolean;\n\texp: number;\n\t/**\n\t * The family name of the user, or last name in most\n\t * Western languages.\n\t */\n\tfamily_name: string;\n\t/**\n\t * The given name of the user, or first name in most\n\t * Western languages.\n\t */\n\tgiven_name: string;\n\thd?: string;\n\tiat: number;\n\tiss: string;\n\tjti?: string;\n\tlocale?: string;\n\tname: string;\n\tnbf?: number;\n\tpicture: string;\n\tsub: string;\n}\n\nexport interface GoogleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const google = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GoogleOptions) => {\n\tconst googleArctic = new Google(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"google\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"google\",\n\t\tname: \"Google\",\n\t\tcreateAuthorizationURL({ state, scopes, codeVerifier }) {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\tconst _scopes = scopes || [\"email\", \"profile\"];\n\t\t\treturn googleArctic.createAuthorizationURL(state, codeVerifier, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\treturn googleArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (!token.idToken) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = parseJWT(token.idToken())?.payload as GoogleProfile;\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: user.sub,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\temail: user.email,\n\t\t\t\t\timage: user.picture,\n\t\t\t\t\temailVerified: user.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: user,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GoogleProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Spotify } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface SpotifyProfile {\n\tid: string;\n\tdisplay_name: string;\n\temail: string;\n\timages: {\n\t\turl: string;\n\t}[];\n}\n\nexport interface SpotifyOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const spotify = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: SpotifyOptions) => {\n\tconst spotifyArctic = new Spotify(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"spotify\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"spotify\",\n\t\tname: \"Spotify\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user-read-email\"];\n\t\t\treturn spotifyArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: spotifyArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<SpotifyProfile>(\n\t\t\t\t\"https://api.spotify.com/v1/me\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.images[0]?.url,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<SpotifyProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitch } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface TwitchProfile {\n\t/**\n\t * The sub of the user\n\t */\n\tsub: string;\n\t/**\n\t * The preferred username of the user\n\t */\n\tpreferred_username: string;\n\t/**\n\t * The email of the user\n\t */\n\temail: string;\n\t/**\n\t * The picture of the user\n\t */\n\tpicture: string;\n}\n\nexport interface TwitchOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitch = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitchOptions) => {\n\tconst twitchArctic = new Twitch(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitch\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitch\",\n\t\tname: \"Twitch\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"activity:write\", \"read\"];\n\t\t\treturn twitchArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: twitchArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitchProfile>(\n\t\t\t\t\"https://api.twitch.tv/helix/users\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.sub,\n\t\t\t\t\tname: profile.preferred_username,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.picture,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitchProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitter } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface TwitterProfile {\n\tdata: {\n\t\t/**\n\t\t * Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools\n\t\t * that cannot handle large integers.\n\t\t */\n\t\tid: string;\n\t\t/** The friendly name of this user, as shown on their profile. */\n\t\tname: string;\n\t\t/** @note Email is currently unsupported by Twitter. */\n\t\temail?: string;\n\t\t/** The Twitter handle (screen name) of this user. */\n\t\tusername: string;\n\t\t/**\n\t\t * The location specified in the user's profile, if the user provided one.\n\t\t * As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.\n\t\t *\n\t\t * To return this field, add `user.fields=location` in the authorization request's query parameter.\n\t\t */\n\t\tlocation?: string;\n\t\t/**\n\t\t * This object and its children fields contain details about text that has a special meaning in the user's description.\n\t\t *\n\t\t *To return this field, add `user.fields=entities` in the authorization request's query parameter.\n\t\t */\n\t\tentities?: {\n\t\t\t/** Contains details about the user's profile website. */\n\t\t\turl: {\n\t\t\t\t/** Contains details about the user's profile website. */\n\t\t\t\turls: Array<{\n\t\t\t\t\t/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */\n\t\t\t\t\tstart: number;\n\t\t\t\t\t/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */\n\t\t\t\t\tend: number;\n\t\t\t\t\t/** The URL in the format entered by the user. */\n\t\t\t\t\turl: string;\n\t\t\t\t\t/** The fully resolved URL. */\n\t\t\t\t\texpanded_url: string;\n\t\t\t\t\t/** The URL as displayed in the user's profile. */\n\t\t\t\t\tdisplay_url: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t\t/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */\n\t\t\tdescription: {\n\t\t\t\thashtags: Array<{\n\t\t\t\t\tstart: number;\n\t\t\t\t\tend: number;\n\t\t\t\t\ttag: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t};\n\t\t/**\n\t\t * Indicate if this user is a verified Twitter user.\n\t\t *\n\t\t * To return this field, add `user.fields=verified` in the authorization request's query parameter.\n\t\t */\n\t\tverified?: boolean;\n\t\t/**\n\t\t * The text of this user's profile description (also known as bio), if the user provided one.\n\t\t *\n\t\t * To return this field, add `user.fields=description` in the authorization request's query parameter.\n\t\t */\n\t\tdescription?: string;\n\t\t/**\n\t\t * The URL specified in the user's profile, if present.\n\t\t *\n\t\t * To return this field, add `user.fields=url` in the authorization request's query parameter.\n\t\t */\n\t\turl?: string;\n\t\t/** The URL to the profile image for this user, as shown on the user's profile. */\n\t\tprofile_image_url?: string;\n\t\tprotected?: boolean;\n\t\t/**\n\t\t * Unique identifier of this user's pinned Tweet.\n\t\t *\n\t\t * You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.\n\t\t */\n\t\tpinned_tweet_id?: string;\n\t\tcreated_at?: string;\n\t};\n\tincludes?: {\n\t\ttweets?: Array<{\n\t\t\tid: string;\n\t\t\ttext: string;\n\t\t}>;\n\t};\n\t[claims: string]: unknown;\n}\n\nexport interface TwitterOption {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitter = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitterOption) => {\n\tconst twitterArctic = new Twitter(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitter\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitter\",\n\t\tname: \"Twitter\",\n\t\tcreateAuthorizationURL(data) {\n\t\t\tconst _scopes = data.scopes || [\"account_info.read\"];\n\t\t\treturn twitterArctic.createAuthorizationURL(\n\t\t\t\tdata.state,\n\t\t\t\tdata.codeVerifier,\n\t\t\t\t_scopes,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Twitter\");\n\t\t\t}\n\t\t\treturn twitterArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitterProfile>(\n\t\t\t\t\"https://api.x.com/2/users/me?user.fields=profile_image_url\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (!profile.data.email) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.data.id,\n\t\t\t\t\tname: profile.data.name,\n\t\t\t\t\temail: profile.data.email,\n\t\t\t\t\timage: profile.data.profile_image_url,\n\t\t\t\t\temailVerified: profile.data.verified || false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitterProfile>;\n};\n","import type { User } from \"../adapters/schema\";\nimport type { oAuthProviderList } from \"../social-providers\";\nimport type { LiteralString } from \"./helper\";\nimport { OAuth2Tokens } from \"arctic\";\n\nexport interface OAuthProvider<\n\tT extends Record<string, any> = Record<string, any>,\n> {\n\tid: LiteralString;\n\tcreateAuthorizationURL: (data: {\n\t\tstate: string;\n\t\tcodeVerifier: string;\n\t\tscopes?: string[];\n\t}) => URL;\n\tname: string;\n\tvalidateAuthorizationCode: (\n\t\tcode: string,\n\t\tcodeVerifier?: string,\n\t) => Promise<OAuth2Tokens>;\n\tgetUserInfo: (token: OAuth2Tokens) => Promise<{\n\t\tuser: Omit<User, \"createdAt\" | \"updatedAt\">;\n\t\tdata: T;\n\t} | null>;\n\trefreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;\n\trevokeToken?: (token: string) => Promise<void>;\n}\n\nexport type OAuthProviderList = typeof oAuthProviderList;\n","import { apple } from \"./apple\";\nimport { discord } from \"./discord\";\nimport { facebook } from \"./facebook\";\nimport { github } from \"./github\";\nimport { google } from \"./google\";\nimport { spotify } from \"./spotify\";\nimport { twitch } from \"./twitch\";\nimport { twitter } from \"./twitter\";\n\nexport const oAuthProviders = {\n\tapple,\n\tdiscord,\n\tfacebook,\n\tgithub,\n\tgoogle,\n\tspotify,\n\ttwitch,\n\ttwitter,\n};\n\nexport const oAuthProviderList = Object.keys(oAuthProviders) as [\n\t\"github\",\n\t...(keyof typeof oAuthProviders)[],\n];\n\nexport * from \"./github\";\nexport * from \"./google\";\nexport * from \"./apple\";\nexport * from \"./discord\";\nexport * from \"./spotify\";\nexport * from \"./twitch\";\nexport * from \"./facebook\";\nexport * from \"./twitter\";\nexport * from \"../types/provider\";\n"],"mappings":";AAAA,OAA6B;AAE7B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;;;ACHrB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAs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,EAAE,MAAM,SAAS,MAAM,IAAI,MAAMC;AAAA,QACtC;AAAA,QACA;AAAA,UACC,QAAQ;AAAA,UACR,SAAS;AAAA,YACR,eAAe,UAAU,MAAM,WAAW;AAAA,UAC3C;AAAA,QACD;AAAA,MACD;AACA,UAAI,OAAO;AACV,eAAO;AAAA,MACR;AACA,UAAI,CAAC,QAAQ,KAAK,OAAO;AACxB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,MAAM;AAAA,UACL,IAAI,QAAQ,KAAK;AAAA,UACjB,MAAM,QAAQ,KAAK;AAAA,UACnB,OAAO,QAAQ,KAAK;AAAA,UACpB,OAAO,QAAQ,KAAK;AAAA,UACpB,eAAe,QAAQ,KAAK,YAAY;AAAA,QACzC;AAAA,QACA,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;;;ACzJA,OAA6B;;;ACMtB,IAAM,iBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,oBAAoB,OAAO,KAAK,cAAc;","names":["betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","error","parseJWT","parseJWT","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch"]}
|
|
1
|
+
{"version":3,"sources":["../src/social-providers/apple.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/social-providers/utils.ts","../src/social-providers/discord.ts","../src/social-providers/facebook.ts","../src/social-providers/github.ts","../src/social-providers/google.ts","../src/social-providers/spotify.ts","../src/social-providers/twitch.ts","../src/social-providers/twitter.ts","../src/types/provider.ts","../src/social-providers/index.ts"],"sourcesContent":["import { OAuth2Tokens } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { parseJWT } from \"oslo/jwt\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\nimport { getRedirectURI } from \"./utils\";\nexport interface AppleProfile {\n\t/**\n\t * The subject registered claim identifies the principal that’s the subject\n\t * of the identity token. Because this token is for your app, the value is\n\t * the unique identifier for the user.\n\t */\n\tsub: string;\n\t/**\n\t * A String value representing the user's email address.\n\t * The email address is either the user's real email address or the proxy\n\t * address, depending on their status private email relay service.\n\t */\n\temail: string;\n\t/**\n\t * A string or Boolean value that indicates whether the service verifies\n\t * the email. The value can either be a string (\"true\" or \"false\") or a\n\t * Boolean (true or false). The system may not verify email addresses for\n\t * Sign in with Apple at Work & School users, and this claim is \"false\" or\n\t * false for those users.\n\t */\n\temail_verified: true | \"true\";\n\t/**\n\t * A string or Boolean value that indicates whether the email that the user\n\t * shares is the proxy address. The value can either be a string (\"true\" or\n\t * \"false\") or a Boolean (true or false).\n\t */\n\tis_private_email: boolean;\n\t/**\n\t * An Integer value that indicates whether the user appears to be a real\n\t * person. Use the value of this claim to mitigate fraud. The possible\n\t * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For\n\t * more information, see ASUserDetectionStatus. This claim is present only\n\t * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14\n\t * and later. The claim isn’t present or supported for web-based apps.\n\t */\n\treal_user_status: number;\n\t/**\n\t * The user’s full name in the format provided during the authorization\n\t * process.\n\t */\n\tname: string;\n}\n\nexport interface AppleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const apple = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: AppleOptions) => {\n\tconst tokenEndpoint = \"https://appleid.apple.com/auth/token\";\n\tredirectURI = getRedirectURI(\"apple\", redirectURI);\n\treturn {\n\t\tid: \"apple\",\n\t\tname: \"Apple\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\", \"name\", \"openid\"];\n\t\t\treturn new URL(\n\t\t\t\t`https://appleid.apple.com/auth/authorize?client_id=${clientId}&response_type=code&redirect_uri=${redirectURI}&scope=${_scope.join(\n\t\t\t\t\t\" \",\n\t\t\t\t)}&state=${state}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code) => {\n\t\t\tconst data = await betterFetch<OAuth2Tokens>(tokenEndpoint, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: new URLSearchParams({\n\t\t\t\t\tclient_id: clientId,\n\t\t\t\t\tclient_secret: clientSecret,\n\t\t\t\t\tgrant_type: \"authorization_code\",\n\t\t\t\t\tcode,\n\t\t\t\t}),\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t},\n\t\t\t});\n\t\t\tif (data.error) {\n\t\t\t\tthrow new BetterAuthError(data.error?.message || \"\");\n\t\t\t}\n\t\t\treturn data.data;\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst data = parseJWT(token.idToken())?.payload as AppleProfile | null;\n\t\t\tif (!data) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: data.sub,\n\t\t\t\t\tname: data.name,\n\t\t\t\t\temail: data.email,\n\t\t\t\t\temailVerified: data.email_verified === \"true\",\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<AppleProfile>;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { getBaseURL } from \"../utils/base-url\";\n\nexport function getRedirectURI(providerId: string, redirectURI?: string) {\n\treturn redirectURI || `${getBaseURL()}/api/auth/callback/${providerId}`;\n}\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Discord } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface DiscordProfile extends Record<string, any> {\n\t/** the user's id (i.e. the numerical snowflake) */\n\tid: string;\n\t/** the user's username, not unique across the platform */\n\tusername: string;\n\t/** the user's Discord-tag */\n\tdiscriminator: string;\n\t/** the user's display name, if it is set */\n\tglobal_name: string | null;\n\t/**\n\t * the user's avatar hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tavatar: string | null;\n\t/** whether the user belongs to an OAuth2 application */\n\tbot?: boolean;\n\t/**\n\t * whether the user is an Official Discord System user (part of the urgent\n\t * message system)\n\t */\n\tsystem?: boolean;\n\t/** whether the user has two factor enabled on their account */\n\tmfa_enabled: boolean;\n\t/**\n\t * the user's banner hash:\n\t * https://discord.com/developers/docs/reference#image-formatting\n\t */\n\tbanner: string | null;\n\n\t/** the user's banner color encoded as an integer representation of hexadecimal color code */\n\taccent_color: number | null;\n\n\t/**\n\t * the user's chosen language option:\n\t * https://discord.com/developers/docs/reference#locales\n\t */\n\tlocale: string;\n\t/** whether the email on this account has been verified */\n\tverified: boolean;\n\t/** the user's email */\n\temail: string;\n\t/**\n\t * the flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tflags: number;\n\t/**\n\t * the type of Nitro subscription on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-premium-types\n\t */\n\tpremium_type: number;\n\t/**\n\t * the public flags on a user's account:\n\t * https://discord.com/developers/docs/resources/user#user-object-user-flags\n\t */\n\tpublic_flags: number;\n\t/** undocumented field; corresponds to the user's custom nickname */\n\tdisplay_name: string | null;\n\t/**\n\t * undocumented field; corresponds to the Discord feature where you can e.g.\n\t * put your avatar inside of an ice cube\n\t */\n\tavatar_decoration: string | null;\n\t/**\n\t * undocumented field; corresponds to the premium feature where you can\n\t * select a custom banner color\n\t */\n\tbanner_color: string | null;\n\t/** undocumented field; the CDN URL of their profile picture */\n\timage_url: string;\n}\n\nexport interface DiscordOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const discord = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: DiscordOptions) => {\n\tconst discordArctic = new Discord(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"discord\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"discord\",\n\t\tname: \"Discord\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scope = scopes || [\"email\"];\n\t\t\treturn discordArctic.createAuthorizationURL(state, _scope);\n\t\t},\n\t\tvalidateAuthorizationCode: discordArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<DiscordProfile>(\n\t\t\t\t\"https://discord.com/api/users/@me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name || profile.username || \"\",\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<DiscordProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Facebook } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface FacebookProfile {\n\tid: string;\n\tname: string;\n\temail: string;\n\temail_verified: boolean;\n\tpicture: {\n\t\tdata: {\n\t\t\theight: number;\n\t\t\tis_silhouette: boolean;\n\t\t\turl: string;\n\t\t\twidth: number;\n\t\t};\n\t};\n}\nexport interface FacebookOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const facebook = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: FacebookOptions) => {\n\tconst facebookArctic = new Facebook(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"facebook\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"facebook\",\n\t\tname: \"Facebook\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"email\", \"public_profile\"];\n\t\t\treturn facebookArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: facebookArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<FacebookProfile>(\n\t\t\t\t\"https://graph.facebook.com/me\",\n\t\t\t\t{\n\t\t\t\t\tauth: {\n\t\t\t\t\t\ttype: \"Bearer\",\n\t\t\t\t\t\ttoken: token.accessToken,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\temailVerified: profile.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<FacebookProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { GitHub } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface GithubProfile {\n\tlogin: string;\n\tid: string;\n\tnode_id: string;\n\tavatar_url: string;\n\tgravatar_id: string;\n\turl: string;\n\thtml_url: string;\n\tfollowers_url: string;\n\tfollowing_url: string;\n\tgists_url: string;\n\tstarred_url: string;\n\tsubscriptions_url: string;\n\torganizations_url: string;\n\trepos_url: string;\n\tevents_url: string;\n\treceived_events_url: string;\n\ttype: string;\n\tsite_admin: boolean;\n\tname: string;\n\tcompany: string;\n\tblog: string;\n\tlocation: string;\n\temail: string;\n\thireable: boolean;\n\tbio: string;\n\ttwitter_username: string;\n\tpublic_repos: string;\n\tpublic_gists: string;\n\tfollowers: string;\n\tfollowing: string;\n\tcreated_at: string;\n\tupdated_at: string;\n\tprivate_gists: string;\n\ttotal_private_repos: string;\n\towned_private_repos: string;\n\tdisk_usage: string;\n\tcollaborators: string;\n\ttwo_factor_authentication: boolean;\n\tplan: {\n\t\tname: string;\n\t\tspace: string;\n\t\tprivate_repos: string;\n\t\tcollaborators: string;\n\t};\n\tfirst_name: string;\n\tlast_name: string;\n}\n\nexport interface GithubOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\nexport const github = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GithubOptions) => {\n\tconst githubArctic = new GitHub(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"github\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"github\",\n\t\tname: \"Github\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user:email\"];\n\t\t\treturn githubArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: githubArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<GithubProfile>(\n\t\t\t\t\"https://api.github.com/user\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet emailVerified = false;\n\t\t\tif (!profile.email) {\n\t\t\t\tconst { data, error } = await betterFetch<\n\t\t\t\t\t{\n\t\t\t\t\t\temail: string;\n\t\t\t\t\t\tprimary: boolean;\n\t\t\t\t\t\tverified: boolean;\n\t\t\t\t\t\tvisibility: \"public\" | \"private\";\n\t\t\t\t\t}[]\n\t\t\t\t>(\"https://api.github.com/user/emails\", {\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t\t\"User-Agent\": \"better-auth\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (!error) {\n\t\t\t\t\tprofile.email = (data.find((e) => e.primary) ?? data[0])\n\t\t\t\t\t\t?.email as string;\n\t\t\t\t\temailVerified =\n\t\t\t\t\t\tdata.find((e) => e.email === profile.email)?.verified ?? false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.avatar_url,\n\t\t\t\t\temailVerified,\n\t\t\t\t\tcreatedAt: new Date(),\n\t\t\t\t\tupdatedAt: new Date(),\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GithubProfile>;\n};\n","import { Google } from \"arctic\";\nimport { parseJWT } from \"oslo/jwt\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface GoogleProfile {\n\taud: string;\n\tazp: string;\n\temail: string;\n\temail_verified: boolean;\n\texp: number;\n\t/**\n\t * The family name of the user, or last name in most\n\t * Western languages.\n\t */\n\tfamily_name: string;\n\t/**\n\t * The given name of the user, or first name in most\n\t * Western languages.\n\t */\n\tgiven_name: string;\n\thd?: string;\n\tiat: number;\n\tiss: string;\n\tjti?: string;\n\tlocale?: string;\n\tname: string;\n\tnbf?: number;\n\tpicture: string;\n\tsub: string;\n}\n\nexport interface GoogleOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const google = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: GoogleOptions) => {\n\tconst googleArctic = new Google(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"google\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"google\",\n\t\tname: \"Google\",\n\t\tcreateAuthorizationURL({ state, scopes, codeVerifier }) {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\tconst _scopes = scopes || [\"email\", \"profile\"];\n\t\t\treturn googleArctic.createAuthorizationURL(state, codeVerifier, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Google\");\n\t\t\t}\n\t\t\treturn googleArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (!token.idToken) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst user = parseJWT(token.idToken())?.payload as GoogleProfile;\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: user.sub,\n\t\t\t\t\tname: user.name,\n\t\t\t\t\temail: user.email,\n\t\t\t\t\timage: user.picture,\n\t\t\t\t\temailVerified: user.email_verified,\n\t\t\t\t},\n\t\t\t\tdata: user,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<GoogleProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Spotify } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface SpotifyProfile {\n\tid: string;\n\tdisplay_name: string;\n\temail: string;\n\timages: {\n\t\turl: string;\n\t}[];\n}\n\nexport interface SpotifyOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const spotify = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: SpotifyOptions) => {\n\tconst spotifyArctic = new Spotify(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"spotify\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"spotify\",\n\t\tname: \"Spotify\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"user-read-email\"];\n\t\t\treturn spotifyArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: spotifyArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<SpotifyProfile>(\n\t\t\t\t\"https://api.spotify.com/v1/me\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.id,\n\t\t\t\t\tname: profile.display_name,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.images[0]?.url,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<SpotifyProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitch } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\n\nexport interface TwitchProfile {\n\t/**\n\t * The sub of the user\n\t */\n\tsub: string;\n\t/**\n\t * The preferred username of the user\n\t */\n\tpreferred_username: string;\n\t/**\n\t * The email of the user\n\t */\n\temail: string;\n\t/**\n\t * The picture of the user\n\t */\n\tpicture: string;\n}\n\nexport interface TwitchOptions {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitch = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitchOptions) => {\n\tconst twitchArctic = new Twitch(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitch\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitch\",\n\t\tname: \"Twitch\",\n\t\tcreateAuthorizationURL({ state, scopes }) {\n\t\t\tconst _scopes = scopes || [\"activity:write\", \"read\"];\n\t\t\treturn twitchArctic.createAuthorizationURL(state, _scopes);\n\t\t},\n\t\tvalidateAuthorizationCode: twitchArctic.validateAuthorizationCode,\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitchProfile>(\n\t\t\t\t\"https://api.twitch.tv/helix/users\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.sub,\n\t\t\t\t\tname: profile.preferred_username,\n\t\t\t\t\temail: profile.email,\n\t\t\t\t\timage: profile.picture,\n\t\t\t\t\temailVerified: false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitchProfile>;\n};\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport { Twitter } from \"arctic\";\nimport type { OAuthProvider } from \".\";\nimport { getRedirectURI } from \"./utils\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport interface TwitterProfile {\n\tdata: {\n\t\t/**\n\t\t * Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools\n\t\t * that cannot handle large integers.\n\t\t */\n\t\tid: string;\n\t\t/** The friendly name of this user, as shown on their profile. */\n\t\tname: string;\n\t\t/** @note Email is currently unsupported by Twitter. */\n\t\temail?: string;\n\t\t/** The Twitter handle (screen name) of this user. */\n\t\tusername: string;\n\t\t/**\n\t\t * The location specified in the user's profile, if the user provided one.\n\t\t * As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.\n\t\t *\n\t\t * To return this field, add `user.fields=location` in the authorization request's query parameter.\n\t\t */\n\t\tlocation?: string;\n\t\t/**\n\t\t * This object and its children fields contain details about text that has a special meaning in the user's description.\n\t\t *\n\t\t *To return this field, add `user.fields=entities` in the authorization request's query parameter.\n\t\t */\n\t\tentities?: {\n\t\t\t/** Contains details about the user's profile website. */\n\t\t\turl: {\n\t\t\t\t/** Contains details about the user's profile website. */\n\t\t\t\turls: Array<{\n\t\t\t\t\t/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */\n\t\t\t\t\tstart: number;\n\t\t\t\t\t/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */\n\t\t\t\t\tend: number;\n\t\t\t\t\t/** The URL in the format entered by the user. */\n\t\t\t\t\turl: string;\n\t\t\t\t\t/** The fully resolved URL. */\n\t\t\t\t\texpanded_url: string;\n\t\t\t\t\t/** The URL as displayed in the user's profile. */\n\t\t\t\t\tdisplay_url: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t\t/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */\n\t\t\tdescription: {\n\t\t\t\thashtags: Array<{\n\t\t\t\t\tstart: number;\n\t\t\t\t\tend: number;\n\t\t\t\t\ttag: string;\n\t\t\t\t}>;\n\t\t\t};\n\t\t};\n\t\t/**\n\t\t * Indicate if this user is a verified Twitter user.\n\t\t *\n\t\t * To return this field, add `user.fields=verified` in the authorization request's query parameter.\n\t\t */\n\t\tverified?: boolean;\n\t\t/**\n\t\t * The text of this user's profile description (also known as bio), if the user provided one.\n\t\t *\n\t\t * To return this field, add `user.fields=description` in the authorization request's query parameter.\n\t\t */\n\t\tdescription?: string;\n\t\t/**\n\t\t * The URL specified in the user's profile, if present.\n\t\t *\n\t\t * To return this field, add `user.fields=url` in the authorization request's query parameter.\n\t\t */\n\t\turl?: string;\n\t\t/** The URL to the profile image for this user, as shown on the user's profile. */\n\t\tprofile_image_url?: string;\n\t\tprotected?: boolean;\n\t\t/**\n\t\t * Unique identifier of this user's pinned Tweet.\n\t\t *\n\t\t * You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.\n\t\t */\n\t\tpinned_tweet_id?: string;\n\t\tcreated_at?: string;\n\t};\n\tincludes?: {\n\t\ttweets?: Array<{\n\t\t\tid: string;\n\t\t\ttext: string;\n\t\t}>;\n\t};\n\t[claims: string]: unknown;\n}\n\nexport interface TwitterOption {\n\tclientId: string;\n\tclientSecret: string;\n\tredirectURI?: string;\n}\n\nexport const twitter = ({\n\tclientId,\n\tclientSecret,\n\tredirectURI,\n}: TwitterOption) => {\n\tconst twitterArctic = new Twitter(\n\t\tclientId,\n\t\tclientSecret,\n\t\tgetRedirectURI(\"twitter\", redirectURI),\n\t);\n\treturn {\n\t\tid: \"twitter\",\n\t\tname: \"Twitter\",\n\t\tcreateAuthorizationURL(data) {\n\t\t\tconst _scopes = data.scopes || [\"account_info.read\"];\n\t\t\treturn twitterArctic.createAuthorizationURL(\n\t\t\t\tdata.state,\n\t\t\t\tdata.codeVerifier,\n\t\t\t\t_scopes,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async (code, codeVerifier) => {\n\t\t\tif (!codeVerifier) {\n\t\t\t\tthrow new BetterAuthError(\"codeVerifier is required for Twitter\");\n\t\t\t}\n\t\t\treturn twitterArctic.validateAuthorizationCode(code, codeVerifier);\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tconst { data: profile, error } = await betterFetch<TwitterProfile>(\n\t\t\t\t\"https://api.x.com/2/users/me?user.fields=profile_image_url\",\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\tAuthorization: `Bearer ${token.accessToken}`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (error) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (!profile.data.email) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: profile.data.id,\n\t\t\t\t\tname: profile.data.name,\n\t\t\t\t\temail: profile.data.email,\n\t\t\t\t\timage: profile.data.profile_image_url,\n\t\t\t\t\temailVerified: profile.data.verified || false,\n\t\t\t\t},\n\t\t\t\tdata: profile,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<TwitterProfile>;\n};\n","import type { User } from \"../adapters/schema\";\nimport type { oAuthProviderList } from \"../social-providers\";\nimport type { LiteralString } from \"./helper\";\nimport { OAuth2Tokens } from \"arctic\";\n\nexport interface OAuthProvider<\n\tT extends Record<string, any> = Record<string, any>,\n> {\n\tid: LiteralString;\n\tcreateAuthorizationURL: (data: {\n\t\tstate: string;\n\t\tcodeVerifier: string;\n\t\tscopes?: string[];\n\t}) => URL;\n\tname: string;\n\tvalidateAuthorizationCode: (\n\t\tcode: string,\n\t\tcodeVerifier?: string,\n\t) => Promise<OAuth2Tokens>;\n\tgetUserInfo: (token: OAuth2Tokens) => Promise<{\n\t\tuser: Omit<User, \"createdAt\" | \"updatedAt\">;\n\t\tdata: T;\n\t} | null>;\n\trefreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;\n\trevokeToken?: (token: string) => Promise<void>;\n}\n\nexport type OAuthProviderList = typeof oAuthProviderList;\n","import { apple } from \"./apple\";\nimport { discord } from \"./discord\";\nimport { facebook } from \"./facebook\";\nimport { github } from \"./github\";\nimport { google } from \"./google\";\nimport { spotify } from \"./spotify\";\nimport { twitch } from \"./twitch\";\nimport { twitter } from \"./twitter\";\n\nexport const oAuthProviders = {\n\tapple,\n\tdiscord,\n\tfacebook,\n\tgithub,\n\tgoogle,\n\tspotify,\n\ttwitch,\n\ttwitter,\n};\n\nexport const oAuthProviderList = Object.keys(oAuthProviders) as [\n\t\"github\",\n\t...(keyof typeof oAuthProviders)[],\n];\n\nexport * from \"./github\";\nexport * from \"./google\";\nexport * from \"./apple\";\nexport * from \"./discord\";\nexport * from \"./spotify\";\nexport * from \"./twitch\";\nexport * from \"./facebook\";\nexport * from \"./twitter\";\nexport * from \"../types/provider\";\n"],"mappings":";AAAA,OAA6B;AAE7B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;;;ACHrB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG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AAA,YACR,eAAe,UAAU,MAAM,WAAW;AAAA,UAC3C;AAAA,QACD;AAAA,MACD;AACA,UAAI,OAAO;AACV,eAAO;AAAA,MACR;AACA,UAAI,CAAC,QAAQ,KAAK,OAAO;AACxB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,MAAM;AAAA,UACL,IAAI,QAAQ,KAAK;AAAA,UACjB,MAAM,QAAQ,KAAK;AAAA,UACnB,OAAO,QAAQ,KAAK;AAAA,UACpB,OAAO,QAAQ,KAAK;AAAA,UACpB,eAAe,QAAQ,KAAK,YAAY;AAAA,QACzC;AAAA,QACA,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;;;ACzJA,OAA6B;;;ACMtB,IAAM,iBAAiB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,IAAM,oBAAoB,OAAO,KAAK,cAAc;","names":["betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","error","parseJWT","parseJWT","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch","betterFetch"]}
|
package/dist/solid.js
CHANGED
|
@@ -36,10 +36,7 @@ function getBaseURL(url, path) {
|
|
|
36
36
|
if (url) {
|
|
37
37
|
return withPath(url, path);
|
|
38
38
|
}
|
|
39
|
-
const env = typeof process !== "undefined" ? process.env :
|
|
40
|
-
//@ts-ignore
|
|
41
|
-
import.meta.env
|
|
42
|
-
) : {};
|
|
39
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
43
40
|
const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
44
41
|
if (fromEnv) {
|
|
45
42
|
return withPath(fromEnv, path);
|
package/dist/solid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/solid.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\t//@ts-ignore\n\tconst env: any =\n\t\ttypeof process !== \"undefined\"\n\t\t\t? process.env\n\t\t\t: typeof import.meta !== \"undefined\"\n\t\t\t\t? //@ts-ignore\n\t\t\t\t\timport.meta.env\n\t\t\t\t: {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n","import type { AuthPlugin, ClientOptions } from \"./type\";\nimport { createAuthFetch, createAuthClient as createClient } from \"./base\";\nimport { useStore } from \"@nanostores/solid\";\nimport type * as SolidJS from \"solid-js\"; //to fix ts error: This is likely not portable. A type annotation is necessary.\nimport type { UnionToIntersection } from \"../types/helper\";\nexport const createAuthClient = <Option extends ClientOptions>(\n\toptions?: Option,\n) => {\n\tconst $fetch = createAuthFetch(options);\n\tconst hooks = options?.authPlugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...(plugin($fetch).integrations?.solid?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as Option[\"authPlugins\"] extends Array<infer Pl>\n\t\t? Pl extends AuthPlugin\n\t\t\t? UnionToIntersection<\n\t\t\t\t\tReturnType<Pl>[\"integrations\"] extends\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\treact?: (useStore: any) => infer R;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? R\n\t\t\t\t\t\t: {}\n\t\t\t\t>\n\t\t\t: {}\n\t\t: {};\n\n\tconst client = createClient(options, hooks);\n\n\tfunction useSession() {\n\t\treturn useStore(client.$atoms.$session);\n\t}\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,UAAU,aAAa;AAAA,EAC/B,SAAS,OAAO;AACf,YAAQ,MAAM,gBAAgB,KAAK;AACnC,WAAO;AAAA,EACR;AACD;AAEA,SAAS,SAAS,KAAa,OAAO,aAAa;AAClD,QAAM,UAAU,aAAa,GAAG;AAChC,MAAI,SAAS;AACZ,WAAO;AAAA,MACN,SAAS,IAAI,IAAI,GAAG,EAAE;AAAA,MACtB,UAAU;AAAA,IACX;AAAA,EACD;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO;AAAA,IACN,SAAS;AAAA,IACT,UAAU,GAAG,GAAG,GAAG,IAAI;AAAA,EACxB;AACD;AAEO,SAAS,WAAW,KAAc,MAAe;AACvD,MAAI,KAAK;AACR,WAAO,SAAS,KAAK,IAAI;AAAA,EAC1B;AAEA,QAAM,MACL,OAAO,YAAY,cAChB,QAAQ,MACR,OAAO,gBAAgB;AAAA;AAAA,IAEvB,YAAY;AAAA,MACX,CAAC;AACN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K,WAAW,eAAe;AAAA,QAClD,MAAM;AAAA,MACP;AAAA,MACA;AAAA,QACC,SAAS,CAAC,SACT,SAAS,eACT,KAAK,WAAW,UAAU,KAC1B,KAAK,WAAW,UAAU;AAAA,QAC3B,MAAM;AAAA,MACP;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,IACA;AAAA,MACC;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD;AACA,SAAO;AACR;;;AMzJA,SAAS,gBAAgB;AAGlB,IAAMA,oBAAmB,CAC/B,YACI;AACJ,QAAM,SAAS,gBAAgB,OAAO;AACtC,QAAM,QAAQ,SAAS,aAAa;AAAA,IACnC,CAAC,KAAK,WAAW;AAChB,aAAO;AAAA,QACN,GAAG;AAAA,QACH,GAAI,OAAO,MAAM,EAAE,cAAc,QAAQ,QAAQ,KAAK,CAAC;AAAA,MACxD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAcA,QAAM,SAAS,iBAAa,SAAS,KAAK;AAE1C,WAAS,aAAa;AACrB,WAAO,SAAS,OAAO,OAAO,QAAQ;AAAA,EACvC;AACA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;","names":["createAuthClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/base.ts","../src/error/better-auth-error.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/solid.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport type { Auth } from \"../auth\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\nimport type { InferRoutes } from \"./path-to-object\";\nimport { createDynamicPathProxy, type AuthProxySignal } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { AuthPlugin, ClientOptions } from \"./type\";\nimport type { UnionToIntersection } from \"../types/helper\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { BetterAuthPlugin } from \"../types/plugins\";\n\n/**\n * used for plugins only\n */\n\nexport const createAuthFetch = (options?: ClientOptions) => {\n\tconst $baseFetch = createFetch();\n\treturn createFetch({\n\t\tmethod: \"GET\",\n\t\t...options,\n\t\tbaseURL: getBaseURL(options?.baseURL).withPath,\n\t\tplugins: [\n\t\t\t...(options?.plugins || []),\n\t\t\t...(options?.authPlugins\n\t\t\t\t?.flatMap((plugin) => plugin($baseFetch).fetchPlugins)\n\t\t\t\t.filter((plugin) => plugin !== undefined) || []),\n\t\t\t...(options?.csrfPlugin !== false ? [csrfPlugin] : []),\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t],\n\t});\n};\n\nexport const createAuthClient = <\n\tO extends ClientOptions = ClientOptions,\n\tAT extends Record<string, any> = {},\n>(\n\toptions?: O,\n\tadditionalActions = {} as AT,\n) => {\n\ttype API = O[\"authPlugins\"] extends Array<any>\n\t\t? (O[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t\t? UnionToIntersection<\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\t\t\tplugin: infer Plug;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t? Plug extends BetterAuthPlugin\n\t\t\t\t\t\t\t\t? Plug[\"endpoints\"]\n\t\t\t\t\t\t\t\t: {}\n\t\t\t\t\t\t\t: {}\n\t\t\t\t\t>\n\t\t\t\t: {}) &\n\t\t\t\tAuth[\"api\"]\n\t\t: Auth[\"api\"];\n\n\tconst $fetch = createAuthFetch(options);\n\n\ttype Plugins = O[\"authPlugins\"] extends Array<AuthPlugin>\n\t\t? Array<ReturnType<O[\"authPlugins\"][number]>[\"plugin\"]>\n\t\t: undefined;\n\t//@ts-expect-error\n\tconst { $session, $sessionSignal } = getSessionAtom<{\n\t\thandler: any;\n\t\tapi: any;\n\t\toptions: {\n\t\t\tdatabase: any;\n\t\t\tplugins: Plugins;\n\t\t};\n\t}>($fetch);\n\n\tlet pluginsActions = {} as Record<string, any>;\n\ttype PluginActions = UnionToIntersection<\n\t\tO[\"authPlugins\"] extends Array<infer Pl>\n\t\t\t? //@ts-expect-error\n\t\t\t\tReturnType<Pl> extends {\n\t\t\t\t\tactions?: infer R;\n\t\t\t\t}\n\t\t\t\t? R\n\t\t\t\t: {}\n\t\t\t: {}\n\t>;\n\n\tconst pluginProxySignals: AuthProxySignal[] = [];\n\tlet pluginSignals: Record<string, PreinitializedWritableAtom<boolean>> = {};\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {};\n\n\tfor (const plugin of options?.authPlugins || []) {\n\t\tconst pl = plugin($fetch);\n\t\tif (pl.authProxySignal) {\n\t\t\tpluginProxySignals.push(...pl.authProxySignal);\n\t\t}\n\t\tif (pl.actions) {\n\t\t\tpluginsActions = {\n\t\t\t\t...pluginsActions,\n\t\t\t\t...pl.actions,\n\t\t\t};\n\t\t}\n\t\tif (pl.signals) {\n\t\t\tpluginSignals = {\n\t\t\t\t...pluginSignals,\n\t\t\t\t...pl.signals,\n\t\t\t};\n\t\t}\n\t\tif (pl.pathMethods) {\n\t\t\tpluginPathMethods = {\n\t\t\t\t...pluginPathMethods,\n\t\t\t\t...pl.pathMethods,\n\t\t\t};\n\t\t}\n\t}\n\n\tconst actions = {\n\t\t$atoms: {\n\t\t\t$session,\n\t\t},\n\t\t$fetch,\n\t\t...(pluginsActions as object),\n\t\t...additionalActions,\n\t};\n\n\ttype Actions = typeof actions & PluginActions;\n\n\tconst proxy = createDynamicPathProxy(\n\t\tactions,\n\t\t$fetch,\n\t\t{\n\t\t\t...pluginPathMethods,\n\t\t\t\"/sign-out\": \"POST\",\n\t\t},\n\t\t[\n\t\t\t{\n\t\t\t\tmatcher: (path) => path === \"/organization/create\",\n\t\t\t\tatom: \"$listOrg\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/organization\"),\n\t\t\t\tatom: \"$activeOrgSignal\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tmatcher: (path) =>\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\"),\n\t\t\t\tatom: \"$sessionSignal\",\n\t\t\t},\n\t\t\t...pluginProxySignals,\n\t\t],\n\t\t{\n\t\t\t$sessionSignal,\n\t\t\t...pluginSignals,\n\t\t},\n\t) as unknown as InferRoutes<API> & Actions;\n\treturn proxy;\n};\n","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","import { BetterAuthError } from \"../error/better-auth-error\";\n\nfunction checkHasPath(url: string): boolean {\n\ttry {\n\t\tconst parsedUrl = new URL(url);\n\t\treturn parsedUrl.pathname !== \"/\";\n\t} catch (error) {\n\t\tconsole.error(\"Invalid URL:\", error);\n\t\treturn false;\n\t}\n}\n\nfunction withPath(url: string, path = \"/api/auth\") {\n\tconst hasPath = checkHasPath(url);\n\tif (hasPath) {\n\t\treturn {\n\t\t\tbaseURL: new URL(url).origin,\n\t\t\twithPath: url,\n\t\t};\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn {\n\t\tbaseURL: url,\n\t\twithPath: `${url}${path}`,\n\t};\n}\n\nexport function getBaseURL(url?: string, path?: string) {\n\tif (url) {\n\t\treturn withPath(url, path);\n\t}\n\tconst env: any = typeof process !== \"undefined\" ? process.env : {};\n\tconst fromEnv =\n\t\tenv.BETTER_AUTH_URL ||\n\t\tenv.AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_AUTH_URL ||\n\t\tenv.NEXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.PUBLIC_AUTH_URL ||\n\t\tenv.PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_BETTER_AUTH_URL ||\n\t\tenv.NUXT_PUBLIC_AUTH_URL;\n\tif (fromEnv) {\n\t\treturn withPath(fromEnv, path);\n\t}\n\n\tconst isDev =\n\t\t!fromEnv && (env.NODE_ENV === \"development\" || env.NODE_ENV === \"test\");\n\tif (isDev) {\n\t\treturn {\n\t\t\tbaseURL: \"http://localhost:3000\",\n\t\t\twithPath: \"http://localhost:3000/api/auth\",\n\t\t};\n\t}\n\tthrow new BetterAuthError(\n\t\t\"Could not infer baseURL from environment variables\",\n\t);\n}\n","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../error/better-auth-error\";\n\nexport const redirectPlugin = {\n\tid: \"redirect\",\n\tname: \"Redirect\",\n\thooks: {\n\t\tonSuccess(context) {\n\t\t\tif (context.data?.url && context.data?.redirect) {\n\t\t\t\twindow.location.href = context.data.url;\n\t\t\t}\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const addCurrentURL = {\n\tid: \"add-current-url\",\n\tname: \"Add current URL\",\n\thooks: {\n\t\tonRequest(context) {\n\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\tconst url = new URL(context.url);\n\t\t\t\turl.searchParams.set(\"currentURL\", window.location.href);\n\t\t\t\tcontext.url = url;\n\t\t\t}\n\t\t\treturn context;\n\t\t},\n\t},\n} satisfies BetterFetchPlugin;\n\nexport const csrfPlugin = {\n\tid: \"csrf\",\n\tname: \"CSRF Check\",\n\tasync init(url, options) {\n\t\tif (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst { data, error } = await betterFetch<{\n\t\t\t\tcsrfToken: string;\n\t\t\t}>(\"/csrf\", {\n\t\t\t\tbody: undefined,\n\t\t\t\tbaseURL: options.baseURL,\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcredentials: \"include\",\n\t\t\t});\n\t\t\tif (error?.status === 404) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (error) {\n\t\t\t\tthrow new BetterAuthError(error.message || \"Failed to get CSRF token.\");\n\t\t\t}\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: data.csrfToken,\n\t\t\t};\n\t\t}\n\t\toptions.credentials = \"include\";\n\t\treturn { url, options };\n\t},\n} satisfies BetterFetchPlugin;\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { LiteralUnion } from \"../types/helper\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs?: ProxyRequest,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { options, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (options?.method) {\n\t\treturn options.method;\n\t}\n\tif (body && Object.keys(body).length > 0) {\n\t\treturn \"POST\";\n\t}\n\treturn \"GET\";\n}\n\nexport type AuthProxySignal = {\n\tatom: LiteralUnion<string, \"$sessionSignal\">;\n\tmatcher: (path: string) => boolean;\n};\n\nexport function createDynamicPathProxy<T extends Record<string, any>>(\n\troutes: T,\n\tclient: BetterFetch,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\t$signal?: AuthProxySignal[],\n\t$signals?: Record<string, PreinitializedWritableAtom<boolean>>,\n): T {\n\tfunction createProxy(path: string[] = []): any {\n\t\treturn new Proxy(function () {}, {\n\t\t\tget(target, prop: string) {\n\t\t\t\tconst fullPath = [...path, prop];\n\t\t\t\tlet current: any = routes;\n\t\t\t\tfor (const segment of fullPath) {\n\t\t\t\t\tif (current && typeof current === \"object\" && segment in current) {\n\t\t\t\t\t\tcurrent = current[segment];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcurrent = undefined;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (typeof current === \"function\") {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\n\t\t\t\treturn createProxy(fullPath);\n\t\t\t},\n\t\t\tapply: async (_, __, args) => {\n\t\t\t\tconst routePath =\n\t\t\t\t\t\"/\" +\n\t\t\t\t\tpath\n\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\tsegment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join(\"/\");\n\n\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, arg);\n\t\t\t\tconst { query, options, ...body } = arg;\n\n\t\t\t\treturn await client(routePath, {\n\t\t\t\t\t...options,\n\t\t\t\t\tbody: method === \"GET\" ? undefined : body,\n\t\t\t\t\tquery: query,\n\t\t\t\t\tmethod,\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tconst signal = $signal?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\tconst signalAtom = $signals?.[signal.atom];\n\t\t\t\t\t\tif (!signalAtom) return;\n\t\t\t\t\t\tsignalAtom.set(!signalAtom.get());\n\t\t\t\t\t\tawait options?.onSuccess?.(context);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\n\treturn createProxy() as T;\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom, computed, task } from \"nanostores\";\nimport type { Auth as BetterAuth } from \"../auth\";\nimport type { Prettify } from \"../types/helper\";\nimport type { InferSession, InferUser } from \"../types/models\";\n\nexport function getSessionAtom<Auth extends BetterAuth>(client: BetterFetch) {\n\ttype UserWithAdditionalFields = InferUser<Auth[\"options\"]>;\n\ttype SessionWithAdditionalFields = InferSession<Auth[\"options\"]>;\n\tconst $signal = atom<boolean>(false);\n\tconst $session = computed($signal, () =>\n\t\ttask(async () => {\n\t\t\tconst session = await client(\"/session\", {\n\t\t\t\tcredentials: \"include\",\n\t\t\t\tmethod: \"GET\",\n\t\t\t});\n\t\t\treturn session.data as {\n\t\t\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\t\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t\t\t} | null;\n\t\t}),\n\t);\n\treturn { $session, $sessionSignal: $signal };\n}\n","import type { AuthPlugin, ClientOptions } from \"./type\";\nimport { createAuthFetch, createAuthClient as createClient } from \"./base\";\nimport { useStore } from \"@nanostores/solid\";\nimport type * as SolidJS from \"solid-js\"; //to fix ts error: This is likely not portable. A type annotation is necessary.\nimport type { UnionToIntersection } from \"../types/helper\";\nexport const createAuthClient = <Option extends ClientOptions>(\n\toptions?: Option,\n) => {\n\tconst $fetch = createAuthFetch(options);\n\tconst hooks = options?.authPlugins?.reduce(\n\t\t(acc, plugin) => {\n\t\t\treturn {\n\t\t\t\t...acc,\n\t\t\t\t...(plugin($fetch).integrations?.solid?.(useStore) || {}),\n\t\t\t};\n\t\t},\n\t\t{} as Record<string, any>,\n\t) as Option[\"authPlugins\"] extends Array<infer Pl>\n\t\t? Pl extends AuthPlugin\n\t\t\t? UnionToIntersection<\n\t\t\t\t\tReturnType<Pl>[\"integrations\"] extends\n\t\t\t\t\t\t| {\n\t\t\t\t\t\t\t\treact?: (useStore: any) => infer R;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t| undefined\n\t\t\t\t\t\t? R\n\t\t\t\t\t\t: {}\n\t\t\t\t>\n\t\t\t: {}\n\t\t: {};\n\n\tconst client = createClient(options, hooks);\n\n\tfunction useSession() {\n\t\treturn useStore(client.$atoms.$session);\n\t}\n\tconst obj = Object.assign(client, {\n\t\tuseSession,\n\t});\n\treturn obj;\n};\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACArB,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC5B,UAAM,OAAO;AAAA,EACd;AACD;;;ACFA,SAAS,aAAa,KAAsB;AAC3C,MAAI;AACH,UAAM,YAAY,IAAI,IAAI,GAAG;AAC7B,WAAO,U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A,EACvC;AACA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAAA,IACjC;AAAA,EACD,CAAC;AACD,SAAO;AACR;","names":["createAuthClient"]}
|
package/dist/svelte.js
CHANGED
|
@@ -36,10 +36,7 @@ function getBaseURL(url, path) {
|
|
|
36
36
|
if (url) {
|
|
37
37
|
return withPath(url, path);
|
|
38
38
|
}
|
|
39
|
-
const env = typeof process !== "undefined" ? process.env :
|
|
40
|
-
//@ts-ignore
|
|
41
|
-
import.meta.env
|
|
42
|
-
) : {};
|
|
39
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
43
40
|
const fromEnv = env.BETTER_AUTH_URL || env.AUTH_URL || env.NEXT_PUBLIC_AUTH_URL || env.NEXT_PUBLIC_BETTER_AUTH_URL || env.PUBLIC_AUTH_URL || env.PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_BETTER_AUTH_URL || env.NUXT_PUBLIC_AUTH_URL;
|
|
44
41
|
if (fromEnv) {
|
|
45
42
|
return withPath(fromEnv, path);
|