better-auth 0.0.8-beta.13 → 0.0.8-beta.15
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/client/plugins.d.ts +4 -4
- package/dist/client.d.ts +3 -3
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/{index-DbgpcctN.d.ts → index-CDbexT2h.d.ts} +2 -2
- package/dist/index.d.ts +47 -13
- package/dist/index.js +26 -25
- package/dist/index.js.map +1 -1
- package/dist/{internal-adapter-Dhk5PFp_.d.ts → internal-adapter-u5BXPnKa.d.ts} +1 -1
- package/dist/next-js.d.ts +25 -5
- package/dist/next-js.js +26 -0
- package/dist/next-js.js.map +1 -1
- package/dist/plugins.d.ts +3 -3
- package/dist/plugins.js +12 -20
- package/dist/plugins.js.map +1 -1
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -1
- package/dist/react.js.map +1 -1
- package/dist/social.d.ts +1 -1
- package/dist/solid-start.d.ts +4 -4
- package/dist/solid.d.ts +3 -3
- package/dist/solid.js +3 -1
- package/dist/solid.js.map +1 -1
- package/dist/svelte-kit.d.ts +5 -5
- package/dist/svelte.d.ts +3 -3
- package/dist/svelte.js +3 -1
- package/dist/svelte.js.map +1 -1
- package/dist/{types-BnynutfB.d.ts → types-DU4I7ndl.d.ts} +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/vue.d.ts +3 -3
- package/dist/vue.js +3 -1
- package/dist/vue.js.map +1 -1
- package/package.json +2 -1
- package/dist/{index-CcxejJTH.d.ts → schema-D8WRBTyM.d.ts} +85 -85
package/dist/client/plugins.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import * as nanostores from 'nanostores';
|
|
|
2
2
|
import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-D6SPoYOh.js';
|
|
3
3
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
4
4
|
import { BetterFetchOption } from '@better-fetch/fetch';
|
|
5
|
-
import { o as organization, M as Member, I as Invitation, u as username } from '../index-
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, M as Member, I as Invitation, u as username } from '../index-CDbexT2h.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-CDbexT2h.js';
|
|
7
7
|
import '../helper-D8dhRz72.js';
|
|
8
|
-
import '../
|
|
8
|
+
import '../schema-D8WRBTyM.js';
|
|
9
9
|
import 'arctic';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import 'better-call';
|
|
12
|
-
import '../internal-adapter-
|
|
12
|
+
import '../internal-adapter-u5BXPnKa.js';
|
|
13
13
|
import 'kysely';
|
|
14
14
|
import '@simplewebauthn/types';
|
|
15
15
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as zod from 'zod';
|
|
2
2
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
3
3
|
import * as nanostores from 'nanostores';
|
|
4
|
-
import { B as BetterAuthOptions, F as FieldAttribute, I as InferFieldOutput } from './internal-adapter-
|
|
4
|
+
import { B as BetterAuthOptions, F as FieldAttribute, I as InferFieldOutput } from './internal-adapter-u5BXPnKa.js';
|
|
5
5
|
import { Auth } from './index.js';
|
|
6
6
|
import { U as UnionToIntersection } from './helper-D8dhRz72.js';
|
|
7
|
-
import { C as ClientOptions, I as InferClientAPI, a as InferActions, A as AuthClientPlugin, b as IsSignal } from './types-
|
|
7
|
+
import { C as ClientOptions, I as InferClientAPI, a as InferActions, A as AuthClientPlugin, b as IsSignal } from './types-DU4I7ndl.js';
|
|
8
8
|
import 'kysely';
|
|
9
|
-
import './
|
|
9
|
+
import './schema-D8WRBTyM.js';
|
|
10
10
|
import 'arctic';
|
|
11
11
|
import 'better-call';
|
|
12
12
|
|
package/dist/client.js
CHANGED
|
@@ -229,7 +229,9 @@ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomLis
|
|
|
229
229
|
if (!matches) return;
|
|
230
230
|
const signal = atoms[matches.signal];
|
|
231
231
|
if (!signal) return;
|
|
232
|
-
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
signal.set(!signal.get());
|
|
234
|
+
}, 0);
|
|
233
235
|
}
|
|
234
236
|
});
|
|
235
237
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/config.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/error/better-auth-error.ts","../src/utils/misc.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/vanilla.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\n\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...options?.fetchOptions,\n\t\tplugins: [\n\t\t\tcsrfPlugin,\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t\t...(options?.fetchOptions?.plugins || []),\n\t\t\t...(options?.plugins\n\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t],\n\t});\n\tconst plugins = options?.plugins || [];\n\tlet pluginsActions = {} as Record<string, any>;\n\tlet pluginsAtoms = {} as Record<string, Atom<any>>;\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {\n\t\t\"/sign-out\": \"POST\",\n\t};\n\tconst atomListeners: AtomListener[] = [\n\t\t{\n\t\t\tsignal: \"_sessionSignal\",\n\t\t\tmatcher(path) {\n\t\t\t\treturn path === \"/sign-out\" || path === \"sign-up/email\";\n\t\t\t},\n\t\t},\n\t];\n\tfor (const plugin of plugins) {\n\t\tif (plugin.getActions) {\n\t\t\tObject.assign(pluginsActions, plugin.getActions?.($fetch));\n\t\t}\n\t\tif (plugin.getAtoms) {\n\t\t\tObject.assign(pluginsAtoms, plugin.getAtoms?.($fetch));\n\t\t}\n\t\tif (plugin.pathMethods) {\n\t\t\tObject.assign(pluginPathMethods, plugin.pathMethods);\n\t\t}\n\t\tif (plugin.atomListeners) {\n\t\t\tatomListeners.push(...plugin.atomListeners);\n\t\t}\n\t}\n\treturn {\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\tpluginPathMethods,\n\t\tatomListeners,\n\t\t$fetch,\n\t};\n};\n","function 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 url;\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn `${url}${path}`;\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.NEXT_PUBLIC_BETTER_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\tif (typeof window !== \"undefined\") {\n\t\treturn withPath(window.location.origin, path);\n\t}\n\n\treturn undefined;\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\tif (typeof window !== \"undefined\") {\n\t\t\t\t\twindow.location.href = context.data.url;\n\t\t\t\t}\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 (typeof window !== \"undefined\") {\n\t\t\t/**\n\t\t\t * If origin is the same as baseURL\n\t\t\t * then we don't need to check the CSRF token.\n\t\t\t */\n\t\t\tconst isTheSameOrigin =\n\t\t\t\tnew URL(options?.baseURL || url).origin === window.location.origin;\n\t\t\tif (isTheSameOrigin) {\n\t\t\t\treturn { url, options };\n\t\t\t}\n\t\t}\n\n\t\tif (!options?.baseURL) {\n\t\t\tthrow new BetterAuthError(\n\t\t\t\t\"API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`\",\n\t\t\t);\n\t\t}\n\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\tcustomFetchImpl: options.customFetchImpl,\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","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","export function capitalizeFirstLetter(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { AuthClientPlugin } from \"./types\";\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: PreinitializedWritableAtom<boolean>;\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\tatoms: Record<string, Atom>,\n\tatomListeners: AuthClientPlugin[\"atomListeners\"],\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\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:\n\t\t\t\t\t\tmethod === \"GET\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t...body,\n\t\t\t\t\t\t\t\t\t...(options?.body || {}),\n\t\t\t\t\t\t\t\t},\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\tawait options?.onSuccess?.(context);\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * We trigger listeners\n\t\t\t\t\t\t */\n\t\t\t\t\t\tconst matches = atomListeners?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!matches) return;\n\t\t\t\t\t\tconst signal = atoms[matches.signal];\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\tsignal.set(!signal.get());\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\";\nimport type { AuthClientPlugin, ClientOptions } from \"./types\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\tclient: BetterFetch,\n) {\n\ttype Plugins = Option[\"plugins\"] extends Array<AuthClientPlugin>\n\t\t? Array<Option[\"plugins\"][number][\"$InferServerPlugin\"]>\n\t\t: undefined;\n\n\ttype Auth = {\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};\n\n\ttype UserWithAdditionalFields = InferUser<\n\t\tAuth extends BetterAuth ? Auth : never\n\t>;\n\n\t//@ts-expect-error\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 { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tIsSignal,\n} from \"./types\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\ntype InferResolvedHooks<O extends ClientOptions> = O[\"plugins\"] extends Array<\n\tinfer Plugin\n>\n\t? Plugin extends AuthClientPlugin\n\t\t? Plugin[\"getAtoms\"] extends (fetch: any) => infer Atoms\n\t\t\t? Atoms extends Record<string, any>\n\t\t\t\t? {\n\t\t\t\t\t\t[key in keyof Atoms as IsSignal<key> extends true\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: key extends string\n\t\t\t\t\t\t\t\t? `use${Capitalize<key>}`\n\t\t\t\t\t\t\t\t: never]: Atoms[key];\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t\t: {}\n\t: {};\n\nexport function createAuthClient<Option extends ClientOptions>(\n\toptions?: Option,\n) {\n\tconst {\n\t\tpluginPathMethods,\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\t$fetch,\n\t\tatomListeners,\n\t} = getClientConfig(options);\n\tlet resolvedHooks: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(pluginsAtoms)) {\n\t\tresolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;\n\t}\n\n\tconst { $session, _sessionSignal } = getSessionAtom<Option>($fetch);\n\tconst routes = {\n\t\t...pluginsActions,\n\t\t...resolvedHooks,\n\t\t$fetch,\n\t\tuseSession: $session,\n\t};\n\tconst proxy = createDynamicPathProxy(\n\t\troutes,\n\t\t$fetch,\n\t\tpluginPathMethods,\n\t\t{\n\t\t\t...pluginsAtoms,\n\t\t\t_sessionSignal,\n\t\t},\n\t\tatomListeners,\n\t);\n\treturn proxy as UnionToIntersection<InferResolvedHooks<Option>> &\n\t\tInferClientAPI<Option> &\n\t\tInferActions<Option> & {\n\t\t\tuseSession: typeof $session;\n\t\t\t$fetch: typeof $fetch;\n\t\t};\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACA5B,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,OA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F;AAAA,IACD,CAAC;AAAA,EACF;AAEA,SAAO,YAAY;AACpB;;;AChGA,SAAS,MAAM,UAAU,YAAY;AAM9B,SAAS,eACf,QACC;AAoBD,QAAM,UAAU,KAAc,KAAK;AACnC,QAAM,WAAW;AAAA,IAAS;AAAA,IAAS,MAClC,KAAK,YAAY;AAChB,YAAM,UAAU,MAAM,OAAO,YAAY;AAAA,QACxC,aAAa;AAAA,QACb,QAAQ;AAAA,MACT,CAAC;AACD,aAAO,QAAQ;AAAA,IAIhB,CAAC;AAAA,EACF;AACA,SAAO,EAAE,UAAU,gBAAgB,QAAQ;AAC5C;;;ACZO,SAAS,iBACf,SACC;AACD,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,gBAAgB,OAAO;AAC3B,MAAI,gBAAqC,CAAC;AAC1C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,YAAY,GAAG;AACxD,kBAAc,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI;AAAA,EACrD;AAEA,QAAM,EAAE,UAAU,eAAe,IAAI,eAAuB,MAAM;AAClE,QAAM,SAAS;AAAA,IACd,GAAG;AAAA,IACH,GAAG;AAAA,IACH;AAAA,IACA,YAAY;AAAA,EACb;AACA,QAAM,QAAQ;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACC,GAAG;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAMR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/client/config.ts","../src/utils/base-url.ts","../src/client/fetch-plugins.ts","../src/error/better-auth-error.ts","../src/utils/misc.ts","../src/client/proxy.ts","../src/client/session-atom.ts","../src/client/vanilla.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/base-url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\n\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...options?.fetchOptions,\n\t\tplugins: [\n\t\t\tcsrfPlugin,\n\t\t\tredirectPlugin,\n\t\t\taddCurrentURL,\n\t\t\t...(options?.fetchOptions?.plugins || []),\n\t\t\t...(options?.plugins\n\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t],\n\t});\n\tconst plugins = options?.plugins || [];\n\tlet pluginsActions = {} as Record<string, any>;\n\tlet pluginsAtoms = {} as Record<string, Atom<any>>;\n\tlet pluginPathMethods: Record<string, \"POST\" | \"GET\"> = {\n\t\t\"/sign-out\": \"POST\",\n\t};\n\tconst atomListeners: AtomListener[] = [\n\t\t{\n\t\t\tsignal: \"_sessionSignal\",\n\t\t\tmatcher(path) {\n\t\t\t\treturn path === \"/sign-out\" || path === \"sign-up/email\";\n\t\t\t},\n\t\t},\n\t];\n\tfor (const plugin of plugins) {\n\t\tif (plugin.getActions) {\n\t\t\tObject.assign(pluginsActions, plugin.getActions?.($fetch));\n\t\t}\n\t\tif (plugin.getAtoms) {\n\t\t\tObject.assign(pluginsAtoms, plugin.getAtoms?.($fetch));\n\t\t}\n\t\tif (plugin.pathMethods) {\n\t\t\tObject.assign(pluginPathMethods, plugin.pathMethods);\n\t\t}\n\t\tif (plugin.atomListeners) {\n\t\t\tatomListeners.push(...plugin.atomListeners);\n\t\t}\n\t}\n\treturn {\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\tpluginPathMethods,\n\t\tatomListeners,\n\t\t$fetch,\n\t};\n};\n","function 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 url;\n\t}\n\tpath = path.startsWith(\"/\") ? path : `/${path}`;\n\treturn `${url}${path}`;\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.NEXT_PUBLIC_BETTER_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\tif (typeof window !== \"undefined\") {\n\t\treturn withPath(window.location.origin, path);\n\t}\n\n\treturn undefined;\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\tif (typeof window !== \"undefined\") {\n\t\t\t\t\twindow.location.href = context.data.url;\n\t\t\t\t}\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 (typeof window !== \"undefined\") {\n\t\t\t/**\n\t\t\t * If origin is the same as baseURL\n\t\t\t * then we don't need to check the CSRF token.\n\t\t\t */\n\t\t\tconst isTheSameOrigin =\n\t\t\t\tnew URL(options?.baseURL || url).origin === window.location.origin;\n\t\t\tif (isTheSameOrigin) {\n\t\t\t\treturn { url, options };\n\t\t\t}\n\t\t}\n\n\t\tif (!options?.baseURL) {\n\t\t\tthrow new BetterAuthError(\n\t\t\t\t\"API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`\",\n\t\t\t);\n\t\t}\n\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\tcustomFetchImpl: options.customFetchImpl,\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","export class BetterAuthError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t}\n}\n","export function capitalizeFirstLetter(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { AuthClientPlugin } from \"./types\";\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: PreinitializedWritableAtom<boolean>;\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\tatoms: Record<string, Atom>,\n\tatomListeners: AuthClientPlugin[\"atomListeners\"],\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\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:\n\t\t\t\t\t\tmethod === \"GET\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t...body,\n\t\t\t\t\t\t\t\t\t...(options?.body || {}),\n\t\t\t\t\t\t\t\t},\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\tawait options?.onSuccess?.(context);\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * We trigger listeners\n\t\t\t\t\t\t */\n\t\t\t\t\t\tconst matches = atomListeners?.find((s) => s.matcher(routePath));\n\t\t\t\t\t\tif (!matches) return;\n\t\t\t\t\t\tconst signal = atoms[matches.signal];\n\t\t\t\t\t\tif (!signal) return;\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * To avoid race conditions we set the signal in a setTimeout\n\t\t\t\t\t\t */\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\t//@ts-expect-error\n\t\t\t\t\t\t\tsignal.set(!signal.get());\n\t\t\t\t\t\t}, 0);\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\";\nimport type { AuthClientPlugin, ClientOptions } from \"./types\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\tclient: BetterFetch,\n) {\n\ttype Plugins = Option[\"plugins\"] extends Array<AuthClientPlugin>\n\t\t? Array<Option[\"plugins\"][number][\"$InferServerPlugin\"]>\n\t\t: undefined;\n\n\ttype Auth = {\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};\n\n\ttype UserWithAdditionalFields = InferUser<\n\t\tAuth extends BetterAuth ? Auth : never\n\t>;\n\n\t//@ts-expect-error\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 { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tIsSignal,\n} from \"./types\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\ntype InferResolvedHooks<O extends ClientOptions> = O[\"plugins\"] extends Array<\n\tinfer Plugin\n>\n\t? Plugin extends AuthClientPlugin\n\t\t? Plugin[\"getAtoms\"] extends (fetch: any) => infer Atoms\n\t\t\t? Atoms extends Record<string, any>\n\t\t\t\t? {\n\t\t\t\t\t\t[key in keyof Atoms as IsSignal<key> extends true\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: key extends string\n\t\t\t\t\t\t\t\t? `use${Capitalize<key>}`\n\t\t\t\t\t\t\t\t: never]: Atoms[key];\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t\t: {}\n\t: {};\n\nexport function createAuthClient<Option extends ClientOptions>(\n\toptions?: Option,\n) {\n\tconst {\n\t\tpluginPathMethods,\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\t$fetch,\n\t\tatomListeners,\n\t} = getClientConfig(options);\n\tlet resolvedHooks: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(pluginsAtoms)) {\n\t\tresolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;\n\t}\n\n\tconst { $session, _sessionSignal } = getSessionAtom<Option>($fetch);\n\tconst routes = {\n\t\t...pluginsActions,\n\t\t...resolvedHooks,\n\t\t$fetch,\n\t\tuseSession: $session,\n\t};\n\tconst proxy = createDynamicPathProxy(\n\t\troutes,\n\t\t$fetch,\n\t\tpluginPathMethods,\n\t\t{\n\t\t\t...pluginsAtoms,\n\t\t\t_sessionSignal,\n\t\t},\n\t\tatomListeners,\n\t);\n\treturn proxy as UnionToIntersection<InferResolvedHooks<Option>> &\n\t\tInferClientAPI<Option> &\n\t\tInferActions<Option> & {\n\t\t\tuseSession: typeof $session;\n\t\t\t$fetch: typeof $fetch;\n\t\t};\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;;;ACA5B,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,EACR;AACA,SAAO,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAC7C,SAAO,GAAG,GAAG,GAAG,IAAI;AACrB;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,UACL,IAAI,mBACJ,IAAI,+BACJ,IAAI,0BACJ,IAAI,+BACJ,IAA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AAE,UAAU,gBAAgB,QAAQ;AAC5C;;;ACZO,SAAS,iBACf,SACC;AACD,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,gBAAgB,OAAO;AAC3B,MAAI,gBAAqC,CAAC;AAC1C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,YAAY,GAAG;AACxD,kBAAc,MAAM,sBAAsB,GAAG,CAAC,EAAE,IAAI;AAAA,EACrD;AAEA,QAAM,EAAE,UAAU,eAAe,IAAI,eAAuB,MAAM;AAClE,QAAM,SAAS;AAAA,IACd,GAAG;AAAA,IACH,GAAG;AAAA,IACH;AAAA,IACA,YAAY;AAAA,EACb;AACA,QAAM,QAAQ;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACC,GAAG;AAAA,MACH;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAMR;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { U as User, S as Session } from './
|
|
1
|
+
import { U as User, S as Session } from './schema-D8WRBTyM.js';
|
|
2
2
|
import * as better_call from 'better-call';
|
|
3
3
|
import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-D6SPoYOh.js';
|
|
4
4
|
import { z, ZodObject, ZodOptional, ZodArray, ZodLiteral } from 'zod';
|
|
5
5
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
6
6
|
import { BetterFetch } from '@better-fetch/fetch';
|
|
7
|
-
import { H as HookEndpointContext } from './internal-adapter-
|
|
7
|
+
import { H as HookEndpointContext } from './internal-adapter-u5BXPnKa.js';
|
|
8
8
|
import * as _simplewebauthn_types from '@simplewebauthn/types';
|
|
9
9
|
import { CredentialDeviceType, PublicKeyCredentialCreationOptionsJSON } from '@simplewebauthn/types';
|
|
10
10
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { O as OAuthProvider, U as User } from './schema-D8WRBTyM.js';
|
|
2
|
+
import * as kysely from 'kysely';
|
|
3
|
+
import { A as AuthContext, B as BetterAuthOptions, F as FieldAttribute, I as InferFieldOutput, a as BetterAuthPlugin } from './internal-adapter-u5BXPnKa.js';
|
|
4
|
+
export { g as FieldAttributeConfig, e as FieldType, f as InferValueType, b as InternalAdapter, d as createFieldAttribute, c as createInternalAdapter } from './internal-adapter-u5BXPnKa.js';
|
|
1
5
|
import { U as UnionToIntersection } from './helper-D8dhRz72.js';
|
|
2
|
-
import { A as AuthContext, B as BetterAuthOptions, F as FieldAttribute, I as InferFieldOutput } from './internal-adapter-Dhk5PFp_.js';
|
|
3
|
-
export { g as FieldAttributeConfig, e as FieldType, f as InferValueType, b as InternalAdapter, d as createFieldAttribute, c as createInternalAdapter } from './internal-adapter-Dhk5PFp_.js';
|
|
4
6
|
import * as zod from 'zod';
|
|
5
7
|
import * as better_call from 'better-call';
|
|
6
8
|
import { Context } from 'better-call';
|
|
7
|
-
import 'kysely';
|
|
8
|
-
import './index-CcxejJTH.js';
|
|
9
9
|
import 'arctic';
|
|
10
10
|
|
|
11
11
|
declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(ctx: C, _options: Option) => {
|
|
12
12
|
handler: (request: Request) => Promise<Response>;
|
|
13
|
-
endpoints: {
|
|
13
|
+
endpoints: Omit<{
|
|
14
14
|
ok: {
|
|
15
15
|
(ctx_0?: Context<"/ok", {
|
|
16
16
|
method: "GET";
|
|
@@ -267,9 +267,6 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
|
|
|
267
267
|
options: {
|
|
268
268
|
method: "GET";
|
|
269
269
|
requireHeaders: true;
|
|
270
|
-
metadata: {
|
|
271
|
-
onClient: "hide";
|
|
272
|
-
};
|
|
273
270
|
};
|
|
274
271
|
headers: Headers;
|
|
275
272
|
};
|
|
@@ -562,7 +559,7 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
|
|
|
562
559
|
method: better_call.Method | better_call.Method[];
|
|
563
560
|
headers: Headers;
|
|
564
561
|
};
|
|
565
|
-
}
|
|
562
|
+
}, "error" | "ok" | "welcome">;
|
|
566
563
|
};
|
|
567
564
|
|
|
568
565
|
declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
|
|
@@ -824,9 +821,6 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
|
|
|
824
821
|
options: {
|
|
825
822
|
method: "GET";
|
|
826
823
|
requireHeaders: true;
|
|
827
|
-
metadata: {
|
|
828
|
-
onClient: "hide";
|
|
829
|
-
};
|
|
830
824
|
};
|
|
831
825
|
headers: Headers;
|
|
832
826
|
};
|
|
@@ -1120,7 +1114,47 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
|
|
|
1120
1114
|
headers: Headers;
|
|
1121
1115
|
};
|
|
1122
1116
|
};
|
|
1123
|
-
options:
|
|
1117
|
+
options: {
|
|
1118
|
+
baseURL: string;
|
|
1119
|
+
basePath: string;
|
|
1120
|
+
secret?: string;
|
|
1121
|
+
socialProvider?: OAuthProvider[];
|
|
1122
|
+
plugins?: BetterAuthPlugin[];
|
|
1123
|
+
advanced?: {
|
|
1124
|
+
useSecureCookies?: boolean;
|
|
1125
|
+
disableCSRFCheck?: boolean;
|
|
1126
|
+
};
|
|
1127
|
+
disableLog?: boolean;
|
|
1128
|
+
database: {
|
|
1129
|
+
provider: "postgres" | "sqlite" | "mysql";
|
|
1130
|
+
url: string;
|
|
1131
|
+
} | kysely.Dialect;
|
|
1132
|
+
user?: {
|
|
1133
|
+
modelName?: string;
|
|
1134
|
+
additionalFields?: Record<string, FieldAttribute>;
|
|
1135
|
+
};
|
|
1136
|
+
session?: {
|
|
1137
|
+
modelName?: string;
|
|
1138
|
+
expiresIn?: number;
|
|
1139
|
+
updateAge?: number;
|
|
1140
|
+
};
|
|
1141
|
+
account?: {
|
|
1142
|
+
modelName?: string;
|
|
1143
|
+
};
|
|
1144
|
+
emailAndPassword?: {
|
|
1145
|
+
enabled: boolean;
|
|
1146
|
+
maxPasswordLength?: number;
|
|
1147
|
+
minPasswordLength?: number;
|
|
1148
|
+
sendResetPasswordToken?: (token: string, user: User) => Promise<void>;
|
|
1149
|
+
sendVerificationEmail?: (email: string, url: string, token: string) => Promise<void>;
|
|
1150
|
+
sendEmailVerificationOnSignUp?: boolean;
|
|
1151
|
+
password?: {
|
|
1152
|
+
hash?: (password: string) => Promise<string>;
|
|
1153
|
+
verify?: (password: string, hash: string) => Promise<boolean>;
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1156
|
+
trustedOrigins?: string[];
|
|
1157
|
+
};
|
|
1124
1158
|
};
|
|
1125
1159
|
type Auth = {
|
|
1126
1160
|
handler: (request: Request) => Promise<Response>;
|
package/dist/index.js
CHANGED
|
@@ -826,18 +826,12 @@ function deleteSessionCookie(ctx) {
|
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
828
|
|
|
829
|
-
// src/client/client-utils.ts
|
|
830
|
-
var HIDE_ON_CLIENT_METADATA = {
|
|
831
|
-
onClient: "hide"
|
|
832
|
-
};
|
|
833
|
-
|
|
834
829
|
// src/api/routes/session.ts
|
|
835
830
|
var getSession = createAuthEndpoint(
|
|
836
831
|
"/session",
|
|
837
832
|
{
|
|
838
833
|
method: "GET",
|
|
839
|
-
requireHeaders: true
|
|
840
|
-
metadata: HIDE_ON_CLIENT_METADATA
|
|
834
|
+
requireHeaders: true
|
|
841
835
|
},
|
|
842
836
|
async (ctx) => {
|
|
843
837
|
try {
|
|
@@ -1017,7 +1011,7 @@ var signInEmail = createAuthEndpoint(
|
|
|
1017
1011
|
currentSession.session.id
|
|
1018
1012
|
);
|
|
1019
1013
|
}
|
|
1020
|
-
const { email, password
|
|
1014
|
+
const { email, password } = ctx.body;
|
|
1021
1015
|
const checkEmail = z3.string().email().safeParse(email);
|
|
1022
1016
|
if (!checkEmail.success) {
|
|
1023
1017
|
throw new APIError2("BAD_REQUEST", {
|
|
@@ -1026,7 +1020,7 @@ var signInEmail = createAuthEndpoint(
|
|
|
1026
1020
|
}
|
|
1027
1021
|
const user = await ctx.context.internalAdapter.findUserByEmail(email);
|
|
1028
1022
|
if (!user) {
|
|
1029
|
-
await ctx.context.password.hash(
|
|
1023
|
+
await ctx.context.password.hash(password);
|
|
1030
1024
|
ctx.context.logger.error("User not found", { email });
|
|
1031
1025
|
throw new APIError2("UNAUTHORIZED", {
|
|
1032
1026
|
message: "Invalid email or password"
|
|
@@ -1050,7 +1044,7 @@ var signInEmail = createAuthEndpoint(
|
|
|
1050
1044
|
}
|
|
1051
1045
|
const validPassword = await ctx.context.password.verify(
|
|
1052
1046
|
currentPassword,
|
|
1053
|
-
|
|
1047
|
+
password
|
|
1054
1048
|
);
|
|
1055
1049
|
if (!validPassword) {
|
|
1056
1050
|
ctx.context.logger.error("Invalid password");
|
|
@@ -1117,6 +1111,11 @@ var generateId = () => {
|
|
|
1117
1111
|
return generateRandomString(36, alphabet("a-z", "0-9"));
|
|
1118
1112
|
};
|
|
1119
1113
|
|
|
1114
|
+
// src/client/client-utils.ts
|
|
1115
|
+
var HIDE_ON_CLIENT_METADATA = {
|
|
1116
|
+
onClient: "hide"
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1120
1119
|
// src/utils/getAccount.ts
|
|
1121
1120
|
function getAccountTokens(tokens) {
|
|
1122
1121
|
const accessToken = tokens.accessToken();
|
|
@@ -1296,13 +1295,6 @@ import { TimeSpan as TimeSpan2 } from "oslo";
|
|
|
1296
1295
|
import { createJWT } from "oslo/jwt";
|
|
1297
1296
|
import { validateJWT } from "oslo/jwt";
|
|
1298
1297
|
import { z as z7 } from "zod";
|
|
1299
|
-
|
|
1300
|
-
// src/crypto/password.ts
|
|
1301
|
-
import { Scrypt } from "oslo/password";
|
|
1302
|
-
var password = new Scrypt();
|
|
1303
|
-
var { hash: hashPassword, verify: verifyPassword } = password;
|
|
1304
|
-
|
|
1305
|
-
// src/api/routes/forget-password.ts
|
|
1306
1298
|
var forgetPassword = createAuthEndpoint(
|
|
1307
1299
|
"/forget-password",
|
|
1308
1300
|
{
|
|
@@ -1632,9 +1624,9 @@ var signUpEmail = createAuthEndpoint(
|
|
|
1632
1624
|
}
|
|
1633
1625
|
});
|
|
1634
1626
|
}
|
|
1635
|
-
const { name, email, password
|
|
1627
|
+
const { name, email, password, image } = ctx.body;
|
|
1636
1628
|
const minPasswordLength = ctx.context.options?.emailAndPassword?.minPasswordLength || 8;
|
|
1637
|
-
if (
|
|
1629
|
+
if (password.length < minPasswordLength) {
|
|
1638
1630
|
ctx.context.logger.error("Password is too short");
|
|
1639
1631
|
return ctx.json(null, {
|
|
1640
1632
|
status: 400,
|
|
@@ -1642,7 +1634,7 @@ var signUpEmail = createAuthEndpoint(
|
|
|
1642
1634
|
});
|
|
1643
1635
|
}
|
|
1644
1636
|
const dbUser = await ctx.context.internalAdapter.findUserByEmail(email);
|
|
1645
|
-
const hash = await ctx.context.password.hash(
|
|
1637
|
+
const hash = await ctx.context.password.hash(password);
|
|
1646
1638
|
if (dbUser?.user) {
|
|
1647
1639
|
return ctx.json(null, {
|
|
1648
1640
|
status: 400,
|
|
@@ -1938,7 +1930,10 @@ var router = (ctx, _options) => {
|
|
|
1938
1930
|
middleware: csrfMiddleware
|
|
1939
1931
|
},
|
|
1940
1932
|
...middlewares
|
|
1941
|
-
]
|
|
1933
|
+
],
|
|
1934
|
+
onError(e) {
|
|
1935
|
+
console.log(e);
|
|
1936
|
+
}
|
|
1942
1937
|
});
|
|
1943
1938
|
};
|
|
1944
1939
|
|
|
@@ -2310,6 +2305,11 @@ function getAdapter(options) {
|
|
|
2310
2305
|
});
|
|
2311
2306
|
}
|
|
2312
2307
|
|
|
2308
|
+
// src/crypto/password.ts
|
|
2309
|
+
import argon2 from "argon2";
|
|
2310
|
+
var hashPassword = argon2.hash;
|
|
2311
|
+
var verifyPassword = argon2.verify;
|
|
2312
|
+
|
|
2313
2313
|
// src/adapters/internal-adapter.ts
|
|
2314
2314
|
import { alphabet as alphabet4, generateRandomString as generateRandomString4 } from "oslo/crypto";
|
|
2315
2315
|
var createInternalAdapter = (adapter, options) => {
|
|
@@ -2473,7 +2473,7 @@ var createInternalAdapter = (adapter, options) => {
|
|
|
2473
2473
|
});
|
|
2474
2474
|
return user;
|
|
2475
2475
|
},
|
|
2476
|
-
updatePassword: async (userId,
|
|
2476
|
+
updatePassword: async (userId, password) => {
|
|
2477
2477
|
const account = await adapter.update({
|
|
2478
2478
|
model: tables.account.tableName,
|
|
2479
2479
|
where: [
|
|
@@ -2487,7 +2487,7 @@ var createInternalAdapter = (adapter, options) => {
|
|
|
2487
2487
|
}
|
|
2488
2488
|
],
|
|
2489
2489
|
update: {
|
|
2490
|
-
password
|
|
2490
|
+
password
|
|
2491
2491
|
}
|
|
2492
2492
|
});
|
|
2493
2493
|
return account;
|
|
@@ -2514,7 +2514,8 @@ var init = (options) => {
|
|
|
2514
2514
|
return {
|
|
2515
2515
|
options: {
|
|
2516
2516
|
...options,
|
|
2517
|
-
baseURL: baseURL ? new URL(baseURL).origin : ""
|
|
2517
|
+
baseURL: baseURL ? new URL(baseURL).origin : "",
|
|
2518
|
+
basePath: options.basePath || "/api/auth"
|
|
2518
2519
|
},
|
|
2519
2520
|
baseURL: baseURL || "",
|
|
2520
2521
|
session: {
|
|
@@ -2554,7 +2555,7 @@ var betterAuth = (options) => {
|
|
|
2554
2555
|
return handler(request);
|
|
2555
2556
|
},
|
|
2556
2557
|
api,
|
|
2557
|
-
options
|
|
2558
|
+
options: authContext.options
|
|
2558
2559
|
};
|
|
2559
2560
|
};
|
|
2560
2561
|
export {
|