better-auth 0.6.2-beta.1 → 0.6.2-beta.2

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.
Files changed (75) hide show
  1. package/dist/chunk-2TWXN67D.cjs +2 -0
  2. package/dist/chunk-2TWXN67D.cjs.map +1 -0
  3. package/dist/chunk-3JIHLTUZ.cjs +2 -0
  4. package/dist/chunk-3JIHLTUZ.cjs.map +1 -0
  5. package/dist/chunk-4HZVKNSE.cjs +2 -0
  6. package/dist/chunk-4HZVKNSE.cjs.map +1 -0
  7. package/dist/chunk-5ZBXSZHE.cjs +2 -0
  8. package/dist/chunk-5ZBXSZHE.cjs.map +1 -0
  9. package/dist/chunk-6DIWT34N.cjs +2 -0
  10. package/dist/chunk-6DIWT34N.cjs.map +1 -0
  11. package/dist/chunk-AAGMZIXH.js +2 -0
  12. package/dist/chunk-AAGMZIXH.js.map +1 -0
  13. package/dist/chunk-AN3H7RRS.cjs +2 -0
  14. package/dist/chunk-AN3H7RRS.cjs.map +1 -0
  15. package/dist/chunk-DIAAB4CL.js +2 -0
  16. package/dist/chunk-DIAAB4CL.js.map +1 -0
  17. package/dist/chunk-DYUTQKLN.js +2 -0
  18. package/dist/chunk-DYUTQKLN.js.map +1 -0
  19. package/dist/chunk-EDQALO4N.js +2 -0
  20. package/dist/chunk-EDQALO4N.js.map +1 -0
  21. package/dist/chunk-EK3FTHVF.cjs +2 -0
  22. package/dist/chunk-EK3FTHVF.cjs.map +1 -0
  23. package/dist/chunk-EP6HCSMM.cjs +2 -0
  24. package/dist/chunk-EP6HCSMM.cjs.map +1 -0
  25. package/dist/chunk-EWV4YOZZ.cjs +2 -0
  26. package/dist/chunk-EWV4YOZZ.cjs.map +1 -0
  27. package/dist/chunk-F23RL5RN.js +2 -0
  28. package/dist/chunk-F23RL5RN.js.map +1 -0
  29. package/dist/chunk-F2I6F73J.cjs +2 -0
  30. package/dist/chunk-F2I6F73J.cjs.map +1 -0
  31. package/dist/chunk-HG45OGSY.js +2 -0
  32. package/dist/chunk-HG45OGSY.js.map +1 -0
  33. package/dist/chunk-HO356XF6.cjs +2 -0
  34. package/dist/chunk-HO356XF6.cjs.map +1 -0
  35. package/dist/chunk-JE4IMN7I.js +2 -0
  36. package/dist/chunk-JE4IMN7I.js.map +1 -0
  37. package/dist/chunk-MEKWVT63.js +2 -0
  38. package/dist/chunk-MEKWVT63.js.map +1 -0
  39. package/dist/chunk-NYR6QJJN.js +2 -0
  40. package/dist/chunk-NYR6QJJN.js.map +1 -0
  41. package/dist/chunk-O2NNQMKV.js +2 -0
  42. package/dist/chunk-O2NNQMKV.js.map +1 -0
  43. package/dist/chunk-PIGNTVN3.js +2 -0
  44. package/dist/chunk-PIGNTVN3.js.map +1 -0
  45. package/dist/chunk-R3WFRS2G.js +2 -0
  46. package/dist/chunk-R3WFRS2G.js.map +1 -0
  47. package/dist/chunk-RNBCUCW5.js +2 -0
  48. package/dist/chunk-RNBCUCW5.js.map +1 -0
  49. package/dist/chunk-VASS7ECW.cjs +2 -0
  50. package/dist/chunk-VASS7ECW.cjs.map +1 -0
  51. package/dist/chunk-VJQZSZQW.js +2 -0
  52. package/dist/chunk-VJQZSZQW.js.map +1 -0
  53. package/dist/chunk-VU6ZABBW.cjs +2 -0
  54. package/dist/chunk-VU6ZABBW.cjs.map +1 -0
  55. package/dist/chunk-VVCADMPK.js +2 -0
  56. package/dist/chunk-VVCADMPK.js.map +1 -0
  57. package/dist/chunk-VWQWJYTW.cjs +2 -0
  58. package/dist/chunk-VWQWJYTW.cjs.map +1 -0
  59. package/dist/chunk-ZUCQGGAR.cjs +2 -0
  60. package/dist/chunk-ZUCQGGAR.cjs.map +1 -0
  61. package/dist/client/plugins.cjs +1 -1
  62. package/dist/client/plugins.js +1 -1
  63. package/dist/client.cjs +1 -1
  64. package/dist/client.js +1 -1
  65. package/dist/plugins.cjs +2 -2
  66. package/dist/plugins.js +1 -1
  67. package/dist/react.cjs +1 -1
  68. package/dist/react.js +1 -1
  69. package/dist/solid.cjs +1 -1
  70. package/dist/solid.js +1 -1
  71. package/dist/svelte.cjs +1 -1
  72. package/dist/svelte.js +1 -1
  73. package/dist/vue.cjs +1 -1
  74. package/dist/vue.js +1 -1
  75. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkZUCQGGARcjs = require('./chunk-ZUCQGGAR.cjs');var _chunk6YSOZOBLcjs = require('./chunk-6YSOZOBL.cjs');function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=_chunkZUCQGGARcjs.a.call(void 0, p),n={};for(let[a,g]of Object.entries(t))n[`use${_chunk6YSOZOBLcjs.a.call(void 0, a)}`]=g;let{$session:c,_sessionSignal:u}=_chunkZUCQGGARcjs.d.call(void 0, e),y={...l,...n,$fetch:e,useSession:c};return _chunkZUCQGGARcjs.b.call(void 0, y,e,f,{...t,_sessionSignal:u},m)}exports.a = O;
2
+ //# sourceMappingURL=chunk-2TWXN67D.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-2TWXN67D.cjs","../src/client/vanilla.ts"],"names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter"],"mappings":"AAAA,iIAAsD,wDAAyC,SCiC/EA,CAAAA,CACfC,CAAAA,CACC,CACD,GAAM,CACL,iBAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CACD,CAAA,CAAIC,iCAAAA,CAAuB,CAAA,CACvBC,CAAAA,CAAqC,CAAC,CAAA,CAC1C,GAAA,CAAA,GAAW,CAACC,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,OAAA,CAAQN,CAAY,CAAA,CACrDI,CAAAA,CAAc,CAAA,GAAA,EAAMG,iCAAAA,CAAyB,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-2TWXN67D.cjs","sourcesContent":[null,"import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\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 BetterAuthClientPlugin\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\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkEWV4YOZZcjs = require('./chunk-EWV4YOZZ.cjs');var m=(e={redirect:!0,twoFactorPage:"/"})=>({id:"two-factor",$InferServerPlugin:{},atomListeners:[{matcher:t=>t.startsWith("/two-factor/"),signal:"_sessionSignal"}],pathMethods:{"/two-factor/disable":"POST","/two-factor/enable":"POST","/two-factor/send-otp":"POST","/two-factor/generate-backup-codes":"POST"},fetchPlugins:[{id:"two-factor",name:"two-factor",hooks:{async onSuccess(t){_optionalChain([t, 'access', _ => _.data, 'optionalAccess', _2 => _2.twoFactorRedirect])&&(e.redirect||e.twoFactorPage)&&typeof window<"u"&&(window.location.href=e.twoFactorPage)}}}]});var _browser = require('@simplewebauthn/browser');var _nanostores = require('nanostores');var f=(e,{_listPasskeys:t})=>({signIn:{passkey:async(r,i)=>{let a=await e("/passkey/generate-authenticate-options",{method:"POST",body:{email:_optionalChain([r, 'optionalAccess', _3 => _3.email])}});if(!a.data)return a;try{let s=await _browser.startAuthentication.call(void 0, a.data,_optionalChain([r, 'optionalAccess', _4 => _4.autoFill])||!1),o=await e("/passkey/verify-authentication",{body:{response:s},..._optionalChain([r, 'optionalAccess', _5 => _5.fetchOptions]),...i,method:"POST"});if(!o.data)return o}catch(s){console.log(s)}}},passkey:{addPasskey:async(r,i)=>{let a=await e("/passkey/generate-register-options",{method:"GET"});if(!a.data)return a;try{let s=await _browser.startRegistration.call(void 0, a.data),o=await e("/passkey/verify-registration",{..._optionalChain([r, 'optionalAccess', _6 => _6.fetchOptions]),...i,body:{response:s,name:_optionalChain([r, 'optionalAccess', _7 => _7.name])},method:"POST"});if(!o.data)return o;t.set(Math.random())}catch(s){return s instanceof _browser.WebAuthnError?s.code==="ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED"?{data:null,error:{message:"previously registered",status:400,statusText:"BAD_REQUEST"}}:s.code==="ERROR_CEREMONY_ABORTED"?{data:null,error:{message:"registration cancelled",status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s.message,status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s instanceof Error?s.message:"unknown error",status:500,statusText:"INTERNAL_SERVER_ERROR"}}}}},$Infer:{}}),O= exports.c =()=>{let e=_nanostores.atom.call(void 0, );return{id:"passkey",$InferServerPlugin:{},getActions:t=>f(t,{_listPasskeys:e}),getAtoms(t){return{listPasskeys:_chunkEWV4YOZZcjs.c.call(void 0, e,"/passkey/list-user-passkeys",t,{method:"GET",credentials:"include"}),_listPasskeys:e}},pathMethods:{"/passkey/register":"POST","/passkey/authenticate":"POST"},atomListeners:[{matcher(t){return t==="/passkey/verify-registration"||t==="/passkey/delete-passkey"},signal:"_listPasskeys"}]}};exports.a = m; exports.b = f; exports.c = O;
2
+ //# sourceMappingURL=chunk-3JIHLTUZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-3JIHLTUZ.cjs","../src/plugins/two-factor/client.ts","../src/plugins/passkey/client.ts"],"names":["twoFactorClient","options","path","context","getPasskeyActions","$fetch","_listPasskeys","opts","response","res","startAuthentication","verified","e","fetchOpts","startRegistration","WebAuthnError","passkeyClient","atom","useAuthQuery"],"mappings":"AAAA,qoBAAwC,ICG3BA,CAAAA,CAAkB,CAC9BC,CAAAA,CAQI,CACH,QAAA,CAAU,CAAA,CAAA,CACV,aAAA,CAAe,GAChB,CAAA,CAAA,EAAA,CAEO,CACN,EAAA,CAAI,YAAA,CACJ,kBAAA,CAAoB,CAAC,CAAA,CACrB,aAAA,CAAe,CACd,CACC,OAAA,CAAUC,CAAAA,EAASA,CAAAA,CAAK,UAAA,CAAW,cAAc,CAAA,CACjD,MAAA,CAAQ,gBACT,CACD,CAAA,CACA,WAAA,CAAa,CACZ,qBAAA,CAAuB,MAAA,CACvB,oBAAA,CAAsB,MAAA,CACtB,sBAAA,CAAwB,MAAA,CACxB,mCAAA,CAAqC,MACtC,CAAA,CACA,YAAA,CAAc,CACb,CACC,EAAA,CAAI,YAAA,CACJ,IAAA,CAAM,YAAA,CACN,KAAA,CAAO,CACN,MAAM,SAAA,CAAUC,CAAAA,CAAS,iBACpBA,CAAAA,mBAAQ,IAAA,6BAAM,mBAAA,EAAA,CACbF,CAAAA,CAAQ,QAAA,EAAYA,CAAAA,CAAQ,aAAA,CAAA,EAC3B,OAAO,MAAA,CAAW,GAAA,EAAA,CACrB,MAAA,CAAO,QAAA,CAAS,IAAA,CAAOA,CAAAA,CAAQ,aAAA,CAInC,CACD,CACD,CACD,CACD,CAAA,CAAA,CChDD,kDAIO,wCAUc,IAERG,CAAAA,CAAoB,CAChCC,CAAAA,CACA,CACC,aAAA,CAAAC,CACD,CAAA,CAAA,EAAA,CA+HO,CACN,MAAA,CAAQ,CAIP,OAAA,CAhIoB,KAAA,CACrBC,CAAAA,CAKAN,CAAAA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,iCAAAA,CACpBZ,CACA,6BAAA,CACAD,CAAAA,CACA,CACC,MAAA,CAAQ,KAAA,CACR,WAAA,CAAa,SACd,CACD,CAAA,CAGC,aAAA,CAAAC,CACD,CACD,CAAA,CACA,WAAA,CAAa,CACZ,mBAAA,CAAqB,MAAA,CACrB,uBAAA,CAAyB,MAC1B,CAAA,CACA,aAAA,CAAe,CACd,CACC,OAAA,CAAQJ,CAAAA,CAAM,CACb,OACCA,CAAAA,GAAS,8BAAA,EACTA,CAAAA,GAAS,yBAEX,CAAA,CACA,MAAA,CAAQ,eACT,CACD,CACD,CACD,CAAA,CAAA,4CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-3JIHLTUZ.cjs","sourcesContent":[null,"import type { BetterAuthClientPlugin } from \"../../client/types\";\nimport type { twoFactor as twoFa } from \"../../plugins/two-factor\";\n\nexport const twoFactorClient = (\n\toptions: {\n\t\ttwoFactorPage: string;\n\t\t/**\n\t\t * Redirect to the two factor page. If twoFactorPage\n\t\t * is not set this will redirect to the root path.\n\t\t * @default true\n\t\t */\n\t\tredirect?: boolean;\n\t} = {\n\t\tredirect: true,\n\t\ttwoFactorPage: \"/\",\n\t},\n) => {\n\treturn {\n\t\tid: \"two-factor\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof twoFa>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/two-factor/\"),\n\t\t\t\tsignal: \"_sessionSignal\",\n\t\t\t},\n\t\t],\n\t\tpathMethods: {\n\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t\"/two-factor/generate-backup-codes\": \"POST\",\n\t\t},\n\t\tfetchPlugins: [\n\t\t\t{\n\t\t\t\tid: \"two-factor\",\n\t\t\t\tname: \"two-factor\",\n\t\t\t\thooks: {\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\tif (options.redirect || options.twoFactorPage) {\n\t\t\t\t\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n","import type { BetterFetch, BetterFetchOption } from \"@better-fetch/fetch\";\nimport {\n\tWebAuthnError,\n\tstartAuthentication,\n\tstartRegistration,\n} from \"@simplewebauthn/browser\";\nimport type {\n\tPublicKeyCredentialCreationOptionsJSON,\n\tPublicKeyCredentialRequestOptionsJSON,\n} from \"@simplewebauthn/types\";\nimport type { Session } from \"inspector\";\nimport type { User } from \"../../db/schema\";\nimport type { passkey as passkeyPl, Passkey } from \"../../plugins\";\nimport type { BetterAuthClientPlugin } from \"../../client/types\";\nimport { useAuthQuery } from \"../../client\";\nimport { atom } from \"nanostores\";\n\nexport const getPasskeyActions = (\n\t$fetch: BetterFetch,\n\t{\n\t\t_listPasskeys,\n\t}: {\n\t\t_listPasskeys: ReturnType<typeof atom<any>>;\n\t},\n) => {\n\tconst signInPasskey = async (\n\t\topts?: {\n\t\t\tautoFill?: boolean;\n\t\t\temail?: string;\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t},\n\t\toptions?: BetterFetchOption,\n\t) => {\n\t\tconst response = await $fetch<PublicKeyCredentialRequestOptionsJSON>(\n\t\t\t\"/passkey/generate-authenticate-options\",\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\temail: opts?.email,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (!response.data) {\n\t\t\treturn response;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startAuthentication(\n\t\t\t\tresponse.data,\n\t\t\t\topts?.autoFill || false,\n\t\t\t);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tsession: Session;\n\t\t\t\tuser: User;\n\t\t\t}>(\"/passkey/verify-authentication\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t},\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...options,\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t}\n\t};\n\n\tconst registerPasskey = async (\n\t\topts?: {\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t\t/**\n\t\t\t * The name of the passkey. This is used to\n\t\t\t * identify the passkey in the UI.\n\t\t\t */\n\t\t\tname?: string;\n\t\t},\n\t\tfetchOpts?: BetterFetchOption,\n\t) => {\n\t\tconst options = await $fetch<PublicKeyCredentialCreationOptionsJSON>(\n\t\t\t\"/passkey/generate-register-options\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t},\n\t\t);\n\t\tif (!options.data) {\n\t\t\treturn options;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startRegistration(options.data);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tpasskey: Passkey;\n\t\t\t}>(\"/passkey/verify-registration\", {\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...fetchOpts,\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\tname: opts?.name,\n\t\t\t\t},\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t\t_listPasskeys.set(Math.random());\n\t\t} catch (e) {\n\t\t\tif (e instanceof WebAuthnError) {\n\t\t\t\tif (e.code === \"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"previously registered\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (e.code === \"ERROR_CEREMONY_ABORTED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"registration cancelled\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdata: null,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: e instanceof Error ? e.message : \"unknown error\",\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\tstatusText: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t};\n\n\treturn {\n\t\tsignIn: {\n\t\t\t/**\n\t\t\t * Sign in with a registered passkey\n\t\t\t */\n\t\t\tpasskey: signInPasskey,\n\t\t},\n\t\tpasskey: {\n\t\t\t/**\n\t\t\t * Add a passkey to the user account\n\t\t\t */\n\t\t\taddPasskey: registerPasskey,\n\t\t},\n\t\t/**\n\t\t * Inferred Internal Types\n\t\t */\n\t\t$Infer: {} as {\n\t\t\tPasskey: Passkey;\n\t\t},\n\t};\n};\n\nexport const passkeyClient = () => {\n\tconst _listPasskeys = atom<any>();\n\treturn {\n\t\tid: \"passkey\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof passkeyPl>,\n\t\tgetActions: ($fetch) =>\n\t\t\tgetPasskeyActions($fetch, {\n\t\t\t\t_listPasskeys,\n\t\t\t}),\n\t\tgetAtoms($fetch) {\n\t\t\tconst listPasskeys = useAuthQuery<Passkey[]>(\n\t\t\t\t_listPasskeys,\n\t\t\t\t\"/passkey/list-user-passkeys\",\n\t\t\t\t$fetch,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tlistPasskeys,\n\t\t\t\t_listPasskeys,\n\t\t\t};\n\t\t},\n\t\tpathMethods: {\n\t\t\t\"/passkey/register\": \"POST\",\n\t\t\t\"/passkey/authenticate\": \"POST\",\n\t\t},\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher(path) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tpath === \"/passkey/verify-registration\" ||\n\t\t\t\t\t\tpath === \"/passkey/delete-passkey\"\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tsignal: \"_listPasskeys\",\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk5ZBXSZHEcjs = require('./chunk-5ZBXSZHE.cjs');var m=(e={redirect:!0,twoFactorPage:"/"})=>({id:"two-factor",$InferServerPlugin:{},atomListeners:[{matcher:t=>t.startsWith("/two-factor/"),signal:"_sessionSignal"}],pathMethods:{"/two-factor/disable":"POST","/two-factor/enable":"POST","/two-factor/send-otp":"POST","/two-factor/generate-backup-codes":"POST"},fetchPlugins:[{id:"two-factor",name:"two-factor",hooks:{async onSuccess(t){_optionalChain([t, 'access', _ => _.data, 'optionalAccess', _2 => _2.twoFactorRedirect])&&(e.redirect||e.twoFactorPage)&&typeof window<"u"&&(window.location.href=e.twoFactorPage)}}}]});var _browser = require('@simplewebauthn/browser');var _nanostores = require('nanostores');var f=(e,{_listPasskeys:t})=>({signIn:{passkey:async(r,i)=>{let a=await e("/passkey/generate-authenticate-options",{method:"POST",body:{email:_optionalChain([r, 'optionalAccess', _3 => _3.email])}});if(!a.data)return a;try{let s=await _browser.startAuthentication.call(void 0, a.data,_optionalChain([r, 'optionalAccess', _4 => _4.autoFill])||!1),o=await e("/passkey/verify-authentication",{body:{response:s},..._optionalChain([r, 'optionalAccess', _5 => _5.fetchOptions]),...i,method:"POST"});if(!o.data)return o}catch(s){console.log(s)}}},passkey:{addPasskey:async(r,i)=>{let a=await e("/passkey/generate-register-options",{method:"GET"});if(!a.data)return a;try{let s=await _browser.startRegistration.call(void 0, a.data),o=await e("/passkey/verify-registration",{..._optionalChain([r, 'optionalAccess', _6 => _6.fetchOptions]),...i,body:{response:s,name:_optionalChain([r, 'optionalAccess', _7 => _7.name])},method:"POST"});if(!o.data)return o;t.set(Math.random())}catch(s){return s instanceof _browser.WebAuthnError?s.code==="ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED"?{data:null,error:{message:"previously registered",status:400,statusText:"BAD_REQUEST"}}:s.code==="ERROR_CEREMONY_ABORTED"?{data:null,error:{message:"registration cancelled",status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s.message,status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s instanceof Error?s.message:"unknown error",status:500,statusText:"INTERNAL_SERVER_ERROR"}}}}},$Infer:{}}),O= exports.c =()=>{let e=_nanostores.atom.call(void 0, );return{id:"passkey",$InferServerPlugin:{},getActions:t=>f(t,{_listPasskeys:e}),getAtoms(t){return{listPasskeys:_chunk5ZBXSZHEcjs.c.call(void 0, e,"/passkey/list-user-passkeys",t,{method:"GET",credentials:"include"}),_listPasskeys:e}},pathMethods:{"/passkey/register":"POST","/passkey/authenticate":"POST"},atomListeners:[{matcher(t){return t==="/passkey/verify-registration"||t==="/passkey/delete-passkey"},signal:"_listPasskeys"}]}};exports.a = m; exports.b = f; exports.c = O;
2
+ //# sourceMappingURL=chunk-4HZVKNSE.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-4HZVKNSE.cjs","../src/plugins/two-factor/client.ts","../src/plugins/passkey/client.ts"],"names":["twoFactorClient","options","path","context","getPasskeyActions","$fetch","_listPasskeys","opts","response","res","startAuthentication","verified","e","fetchOpts","startRegistration","WebAuthnError","passkeyClient","atom","useAuthQuery"],"mappings":"AAAA,qoBAAwC,ICG3BA,CAAAA,CAAkB,CAC9BC,CAAAA,CAQI,CACH,QAAA,CAAU,CAAA,CAAA,CACV,aAAA,CAAe,GAChB,CAAA,CAAA,EAAA,CAEO,CACN,EAAA,CAAI,YAAA,CACJ,kBAAA,CAAoB,CAAC,CAAA,CACrB,aAAA,CAAe,CACd,CACC,OAAA,CAAUC,CAAAA,EAASA,CAAAA,CAAK,UAAA,CAAW,cAAc,CAAA,CACjD,MAAA,CAAQ,gBACT,CACD,CAAA,CACA,WAAA,CAAa,CACZ,qBAAA,CAAuB,MAAA,CACvB,oBAAA,CAAsB,MAAA,CACtB,sBAAA,CAAwB,MAAA,CACxB,mCAAA,CAAqC,MACtC,CAAA,CACA,YAAA,CAAc,CACb,CACC,EAAA,CAAI,YAAA,CACJ,IAAA,CAAM,YAAA,CACN,KAAA,CAAO,CACN,MAAM,SAAA,CAAUC,CAAAA,CAAS,iBACpBA,CAAAA,mBAAQ,IAAA,6BAAM,mBAAA,EAAA,CACbF,CAAAA,CAAQ,QAAA,EAAYA,CAAAA,CAAQ,aAAA,CAAA,EAC3B,OAAO,MAAA,CAAW,GAAA,EAAA,CACrB,MAAA,CAAO,QA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,CAAAA,CAAgBW,8BAAAA,CAAU,CAChC,MAAO,CACN,EAAA,CAAI,SAAA,CACJ,kBAAA,CAAoB,CAAC,CAAA,CACrB,UAAA,CAAaZ,CAAAA,EACZD,CAAAA,CAAkBC,CAAAA,CAAQ,CACzB,aAAA,CAAAC,CACD,CAAC,CAAA,CACF,QAAA,CAASD,CAAAA,CAAQ,CAUhB,MAAO,CACN,YAAA,CAVoBa,iCAAAA,CACpBZ,CACA,6BAAA,CACAD,CAAAA,CACA,CACC,MAAA,CAAQ,KAAA,CACR,WAAA,CAAa,SACd,CACD,CAAA,CAGC,aAAA,CAAAC,CACD,CACD,CAAA,CACA,WAAA,CAAa,CACZ,mBAAA,CAAqB,MAAA,CACrB,uBAAA,CAAyB,MAC1B,CAAA,CACA,aAAA,CAAe,CACd,CACC,OAAA,CAAQJ,CAAAA,CAAM,CACb,OACCA,CAAAA,GAAS,8BAAA,EACTA,CAAAA,GAAS,yBAEX,CAAA,CACA,MAAA,CAAQ,eACT,CACD,CACD,CACD,CAAA,CAAA,4CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-4HZVKNSE.cjs","sourcesContent":[null,"import type { BetterAuthClientPlugin } from \"../../client/types\";\nimport type { twoFactor as twoFa } from \"../../plugins/two-factor\";\n\nexport const twoFactorClient = (\n\toptions: {\n\t\ttwoFactorPage: string;\n\t\t/**\n\t\t * Redirect to the two factor page. If twoFactorPage\n\t\t * is not set this will redirect to the root path.\n\t\t * @default true\n\t\t */\n\t\tredirect?: boolean;\n\t} = {\n\t\tredirect: true,\n\t\ttwoFactorPage: \"/\",\n\t},\n) => {\n\treturn {\n\t\tid: \"two-factor\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof twoFa>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/two-factor/\"),\n\t\t\t\tsignal: \"_sessionSignal\",\n\t\t\t},\n\t\t],\n\t\tpathMethods: {\n\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t\"/two-factor/generate-backup-codes\": \"POST\",\n\t\t},\n\t\tfetchPlugins: [\n\t\t\t{\n\t\t\t\tid: \"two-factor\",\n\t\t\t\tname: \"two-factor\",\n\t\t\t\thooks: {\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\tif (options.redirect || options.twoFactorPage) {\n\t\t\t\t\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n","import type { BetterFetch, BetterFetchOption } from \"@better-fetch/fetch\";\nimport {\n\tWebAuthnError,\n\tstartAuthentication,\n\tstartRegistration,\n} from \"@simplewebauthn/browser\";\nimport type {\n\tPublicKeyCredentialCreationOptionsJSON,\n\tPublicKeyCredentialRequestOptionsJSON,\n} from \"@simplewebauthn/types\";\nimport type { Session } from \"inspector\";\nimport type { User } from \"../../db/schema\";\nimport type { passkey as passkeyPl, Passkey } from \"../../plugins\";\nimport type { BetterAuthClientPlugin } from \"../../client/types\";\nimport { useAuthQuery } from \"../../client\";\nimport { atom } from \"nanostores\";\n\nexport const getPasskeyActions = (\n\t$fetch: BetterFetch,\n\t{\n\t\t_listPasskeys,\n\t}: {\n\t\t_listPasskeys: ReturnType<typeof atom<any>>;\n\t},\n) => {\n\tconst signInPasskey = async (\n\t\topts?: {\n\t\t\tautoFill?: boolean;\n\t\t\temail?: string;\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t},\n\t\toptions?: BetterFetchOption,\n\t) => {\n\t\tconst response = await $fetch<PublicKeyCredentialRequestOptionsJSON>(\n\t\t\t\"/passkey/generate-authenticate-options\",\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\temail: opts?.email,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (!response.data) {\n\t\t\treturn response;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startAuthentication(\n\t\t\t\tresponse.data,\n\t\t\t\topts?.autoFill || false,\n\t\t\t);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tsession: Session;\n\t\t\t\tuser: User;\n\t\t\t}>(\"/passkey/verify-authentication\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t},\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...options,\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t}\n\t};\n\n\tconst registerPasskey = async (\n\t\topts?: {\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t\t/**\n\t\t\t * The name of the passkey. This is used to\n\t\t\t * identify the passkey in the UI.\n\t\t\t */\n\t\t\tname?: string;\n\t\t},\n\t\tfetchOpts?: BetterFetchOption,\n\t) => {\n\t\tconst options = await $fetch<PublicKeyCredentialCreationOptionsJSON>(\n\t\t\t\"/passkey/generate-register-options\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t},\n\t\t);\n\t\tif (!options.data) {\n\t\t\treturn options;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startRegistration(options.data);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tpasskey: Passkey;\n\t\t\t}>(\"/passkey/verify-registration\", {\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...fetchOpts,\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\tname: opts?.name,\n\t\t\t\t},\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t\t_listPasskeys.set(Math.random());\n\t\t} catch (e) {\n\t\t\tif (e instanceof WebAuthnError) {\n\t\t\t\tif (e.code === \"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"previously registered\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (e.code === \"ERROR_CEREMONY_ABORTED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"registration cancelled\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdata: null,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: e instanceof Error ? e.message : \"unknown error\",\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\tstatusText: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t};\n\n\treturn {\n\t\tsignIn: {\n\t\t\t/**\n\t\t\t * Sign in with a registered passkey\n\t\t\t */\n\t\t\tpasskey: signInPasskey,\n\t\t},\n\t\tpasskey: {\n\t\t\t/**\n\t\t\t * Add a passkey to the user account\n\t\t\t */\n\t\t\taddPasskey: registerPasskey,\n\t\t},\n\t\t/**\n\t\t * Inferred Internal Types\n\t\t */\n\t\t$Infer: {} as {\n\t\t\tPasskey: Passkey;\n\t\t},\n\t};\n};\n\nexport const passkeyClient = () => {\n\tconst _listPasskeys = atom<any>();\n\treturn {\n\t\tid: \"passkey\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof passkeyPl>,\n\t\tgetActions: ($fetch) =>\n\t\t\tgetPasskeyActions($fetch, {\n\t\t\t\t_listPasskeys,\n\t\t\t}),\n\t\tgetAtoms($fetch) {\n\t\t\tconst listPasskeys = useAuthQuery<Passkey[]>(\n\t\t\t\t_listPasskeys,\n\t\t\t\t\"/passkey/list-user-passkeys\",\n\t\t\t\t$fetch,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tlistPasskeys,\n\t\t\t\t_listPasskeys,\n\t\t\t};\n\t\t},\n\t\tpathMethods: {\n\t\t\t\"/passkey/register\": \"POST\",\n\t\t\t\"/passkey/authenticate\": \"POST\",\n\t\t},\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher(path) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tpath === \"/passkey/verify-registration\" ||\n\t\t\t\t\t\tpath === \"/passkey/delete-passkey\"\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tsignal: \"_listPasskeys\",\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkH5ZHLIW4cjs = require('./chunk-H5ZHLIW4.cjs');var _chunkWNGZ4EQPcjs = require('./chunk-WNGZ4EQP.cjs');var _fetch = require('@better-fetch/fetch');var _nanostores = require('nanostores');var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){_optionalChain([e, 'access', _ => _.data, 'optionalAccess', _2 => _2.url])&&_optionalChain([e, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.redirect])&&typeof window<"u"&&(window.location.href=e.data.url)}}},R={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},b={id:"csrf",name:"CSRF Check",async init(e,r){if(_optionalChain([r, 'optionalAccess', _5 => _5.method])!=="GET"){r=r||{};let a="credentials"in Request.prototype,{data:s,error:n}=await _fetch.betterFetch.call(void 0, "/csrf",{body:void 0,baseURL:r.baseURL,plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(n){if(n.status===404)throw new (0, _chunkWNGZ4EQPcjs.a)("CSRF 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).");if(n.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new (0, _chunkWNGZ4EQPcjs.a)("Failed to fetch CSRF token: "+n.message)}let c=_optionalChain([s, 'optionalAccess', _6 => _6.csrfToken]);r.body={..._optionalChain([r, 'optionalAccess', _7 => _7.body]),csrfToken:c}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,a=_fetch.createFetch.call(void 0, {baseURL:_chunkH5ZHLIW4cjs.a.call(void 0, _optionalChain([e, 'optionalAccess', _8 => _8.fetchOptions, 'optionalAccess', _9 => _9.baseURL])||_optionalChain([e, 'optionalAccess', _10 => _10.baseURL])),...r?{credentials:"include"}:{},method:"GET",..._optionalChain([e, 'optionalAccess', _11 => _11.fetchOptions]),plugins:_optionalChain([e, 'optionalAccess', _12 => _12.disableDefaultFetchPlugins])?_optionalChain([e, 'access', _13 => _13.fetchOptions, 'optionalAccess', _14 => _14.plugins]):[..._optionalChain([e, 'optionalAccess', _15 => _15.disableCSRFTokenCheck])?[]:[b],F,R,..._optionalChain([e, 'optionalAccess', _16 => _16.fetchOptions, 'optionalAccess', _17 => _17.plugins, 'optionalAccess', _18 => _18.filter, 'call', _19 => _19(t=>t!==void 0)])||[],..._optionalChain([e, 'optionalAccess', _20 => _20.plugins, 'optionalAccess', _21 => _21.flatMap, 'call', _22 => _22(t=>t.fetchPlugins), 'access', _23 => _23.filter, 'call', _24 => _24(t=>t!==void 0)])||[]]}),s=_optionalChain([e, 'optionalAccess', _25 => _25.plugins])||[],n={},c={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},i=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of s)t.getActions&&Object.assign(n,_optionalChain([t, 'access', _26 => _26.getActions, 'optionalCall', _27 => _27(a)])),t.getAtoms&&Object.assign(c,_optionalChain([t, 'access', _28 => _28.getAtoms, 'optionalCall', _29 => _29(a)])),t.pathMethods&&Object.assign(u,t.pathMethods),t.atomListeners&&i.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:c,pluginPathMethods:u,atomListeners:i,$fetch:a}};function E(e,r,a){let s=r[e],{fetchOptions:n,query:c,...u}=a||{};return s||(_optionalChain([n, 'optionalAccess', _30 => _30.method])?n.method:u&&Object.keys(u).length>0?"POST":"GET")}function Q(e,r,a,s,n){function c(u=[]){return new Proxy(function(){},{get(i,t){let l=[...u,t],o=e;for(let d of l)if(o&&typeof o=="object"&&d in o)o=o[d];else{o=void 0;break}return typeof o=="function"?o:c(l)},apply:async(i,t,l)=>{let o="/"+u.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(o,a,d);return await r(o,{...f,body:y==="GET"?void 0:{...B,..._optionalChain([f, 'optionalAccess', _31 => _31.body])||{}},query:A||_optionalChain([f, 'optionalAccess', _32 => _32.query]),method:y,async onSuccess(g){await _optionalChain([f, 'optionalAccess', _33 => _33.onSuccess, 'optionalCall', _34 => _34(g)]);let h=_optionalChain([n, 'optionalAccess', _35 => _35.find, 'call', _36 => _36(w=>w.matcher(o))]);if(!h)return;let p=s[h.signal];if(!p)return;let C=p.get();setTimeout(()=>{p.set(!C)},10)}})}})}return c()}var O=(e,r,a,s)=>{let n=_nanostores.atom.call(void 0, {data:null,error:null,isPending:!0,isRefetching:!1}),c=()=>{let i=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;return a(r,{...i,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await _optionalChain([i, 'optionalAccess', _37 => _37.onSuccess, 'optionalCall', _38 => _38(t)])},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await _optionalChain([i, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40(t)])},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await _optionalChain([i, 'optionalAccess', _41 => _41.onRequest, 'optionalCall', _42 => _42(t)])}})};e=Array.isArray(e)?e:[e];let u=!1;for(let i of e)i.subscribe(()=>{u?c():_nanostores.onMount.call(void 0, n,()=>(c(),u=!0,()=>{n.off(),i.off()}))});return n};function X(e){let r=_nanostores.atom.call(void 0, !1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}exports.a = $; exports.b = Q; exports.c = O; exports.d = X;
2
+ //# sourceMappingURL=chunk-5ZBXSZHE.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-5ZBXSZHE.cjs","../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts"],"names":["redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","isCredentialsSupported","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","$fetch","createFetch","getBaseURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","createProxy","target","prop","fullPath","current","segment","_","__","routePath","letter"],"mappings":"AAAA,qoBAAwC,wDAAyC,4CCArD,wCAEF,ICCbA,CAAAA,CAAiB,CAC7B,EAAA,CAAI,UAAA,CACJ,IAAA,CAAM,UAAA,CACN,KAAA,CAAO,CACN,SAAA,CAAUC,CAAAA,CAAS,iBACdA,CAAAA,mBAAQ,IAAA,6BAAM,KAAA,kBAAOA,CAAAA,qBAAQ,IAAA,6BAAM,UAAA,EAClC,OAAO,MAAA,CAAW,GAAA,EAAA,CACrB,MAAA,CAAO,QAAA,CAAS,IAAA,CAAOA,CAAAA,CAAQ,IAAA,CAAK,GAAA,CAGvC,CACD,CACD,CAAA,CAEaC,CAAAA,CAAgB,CAC5B,EAAA,CAAI,iBAAA,CACJ,IAAA,CAAM,iBAAA,CACN,KAAA,CAAO,CACN,SAAA,CAAUD,CAAAA,CAAS,CAClB,EAAA,CAAI,OAAO,MAAA,CAAW,GAAA,CAAa,CAClC,IAAME,CAAAA,CAAM,IAAI,GAAA,CAAIF,CAAAA,CAAQ,GAAG,CAAA,CAC/BE,CAAAA,CAAI,YAAA,CAAa,GAAA,CAAI,YAAA,CAAc,MAAA,CAAO,QAAA,CAAS,IAAI,CAAA,CACvDF,CAAAA,CAAQ,GAAA,CAAME,CACf,CACA,OAAOF,CACR,CACD,CACD,CAAA,CAEaG,CAAAA,CAAa,CACzB,EAAA,CAAI,MAAA,CACJ,IAAA,CAAM,YAAA,CACN,MAAM,IAAA,CAAKD,CAAAA,CAAKE,CAAAA,CAAS,CACxB,EAAA,iBAAIA,CAAAA,6BAAS,QAAA,GAAW,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,CAChC,GAAA,CAAIa,CAAAA,CAAQC,CAAAA,CAAc,CACzB,IAAMC,CAAAA,CAAW,CAAC,GAAGf,CAAAA,CAAMc,CAAI,CAAA,CAC3BE,CAAAA,CAAeP,CAAAA,CACnB,GAAA,CAAA,IAAWQ,EAAAA,GAAWF,CAAAA,CACrB,EAAA,CAAIC,CAAAA,EAAW,OAAOA,CAAAA,EAAY,QAAA,EAAYC,EAAAA,GAAWD,CAAAA,CACxDA,CAAAA,CAAUA,CAAAA,CAAQC,CAAO,CAAA,CAAA,IACnB,CACND,CAAAA,CAAU,KAAA,CAAA,CACV,KACD,CAED,OAAI,OAAOA,CAAAA,EAAY,UAAA,CACfA,CAAAA,CAEDJ,CAAAA,CAAYG,CAAQ,CAC5B,CAAA,CACA,KAAA,CAAO,KAAA,CAAOG,CAAAA,CAAGC,CAAAA,CAAIhB,CAAAA,CAAAA,EAAS,CAC7B,IAAMiB,CAAAA,CACL,GAAA,CACApB,CAAAA,CACE,GAAA,CAAKiB,CAAAA,EACLA,CAAAA,CAAQ,OAAA,CAAQ,QAAA,CAAWI,CAAAA,EAAW,CAAA,CAAA,EAAIA,CAAAA,CAAO,WAAA,CAAY,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-5ZBXSZHE.cjs","sourcesContent":[null,"import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\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\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkH5ZHLIW4cjs = require('./chunk-H5ZHLIW4.cjs');var _chunkWNGZ4EQPcjs = require('./chunk-WNGZ4EQP.cjs');var _fetch = require('@better-fetch/fetch');var _nanostores = require('nanostores');var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){_optionalChain([e, 'access', _ => _.data, 'optionalAccess', _2 => _2.url])&&_optionalChain([e, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.redirect])&&typeof window<"u"&&(window.location.href=e.data.url)}}},R={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},b={id:"csrf",name:"CSRF Check",async init(e,r){if(_optionalChain([r, 'optionalAccess', _5 => _5.method])!=="GET"){r=r||{};let s="credentials"in Request.prototype,{data:i,error:n}=await _fetch.betterFetch.call(void 0, "/csrf",{body:void 0,baseURL:r.baseURL,credentials:s?"include":"same-origin",plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(n){if(n.status===404)throw new (0, _chunkWNGZ4EQPcjs.a)("CSRF 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).");if(n.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new (0, _chunkWNGZ4EQPcjs.a)("Failed to fetch CSRF token: "+n.message)}let c=_optionalChain([i, 'optionalAccess', _6 => _6.csrfToken]);r.body={..._optionalChain([r, 'optionalAccess', _7 => _7.body]),csrfToken:c}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,s=_fetch.createFetch.call(void 0, {baseURL:_chunkH5ZHLIW4cjs.a.call(void 0, _optionalChain([e, 'optionalAccess', _8 => _8.fetchOptions, 'optionalAccess', _9 => _9.baseURL])||_optionalChain([e, 'optionalAccess', _10 => _10.baseURL])),...r?{credentials:"include"}:{},method:"GET",..._optionalChain([e, 'optionalAccess', _11 => _11.fetchOptions]),plugins:_optionalChain([e, 'optionalAccess', _12 => _12.disableDefaultFetchPlugins])?_optionalChain([e, 'access', _13 => _13.fetchOptions, 'optionalAccess', _14 => _14.plugins]):[..._optionalChain([e, 'optionalAccess', _15 => _15.disableCSRFTokenCheck])?[]:[b],F,R,..._optionalChain([e, 'optionalAccess', _16 => _16.fetchOptions, 'optionalAccess', _17 => _17.plugins, 'optionalAccess', _18 => _18.filter, 'call', _19 => _19(t=>t!==void 0)])||[],..._optionalChain([e, 'optionalAccess', _20 => _20.plugins, 'optionalAccess', _21 => _21.flatMap, 'call', _22 => _22(t=>t.fetchPlugins), 'access', _23 => _23.filter, 'call', _24 => _24(t=>t!==void 0)])||[]]}),i=_optionalChain([e, 'optionalAccess', _25 => _25.plugins])||[],n={},c={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of i)t.getActions&&Object.assign(n,_optionalChain([t, 'access', _26 => _26.getActions, 'optionalCall', _27 => _27(s)])),t.getAtoms&&Object.assign(c,_optionalChain([t, 'access', _28 => _28.getAtoms, 'optionalCall', _29 => _29(s)])),t.pathMethods&&Object.assign(u,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:c,pluginPathMethods:u,atomListeners:o,$fetch:s}};function E(e,r,s){let i=r[e],{fetchOptions:n,query:c,...u}=s||{};return i||(_optionalChain([n, 'optionalAccess', _30 => _30.method])?n.method:u&&Object.keys(u).length>0?"POST":"GET")}function Q(e,r,s,i,n){function c(u=[]){return new Proxy(function(){},{get(o,t){let l=[...u,t],a=e;for(let d of l)if(a&&typeof a=="object"&&d in a)a=a[d];else{a=void 0;break}return typeof a=="function"?a:c(l)},apply:async(o,t,l)=>{let a="/"+u.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(a,s,d);return await r(a,{...f,body:y==="GET"?void 0:{...B,..._optionalChain([f, 'optionalAccess', _31 => _31.body])||{}},query:A||_optionalChain([f, 'optionalAccess', _32 => _32.query]),method:y,async onSuccess(g){await _optionalChain([f, 'optionalAccess', _33 => _33.onSuccess, 'optionalCall', _34 => _34(g)]);let h=_optionalChain([n, 'optionalAccess', _35 => _35.find, 'call', _36 => _36(w=>w.matcher(a))]);if(!h)return;let p=i[h.signal];if(!p)return;let C=p.get();setTimeout(()=>{p.set(!C)},10)}})}})}return c()}var O=(e,r,s,i)=>{let n=_nanostores.atom.call(void 0, {data:null,error:null,isPending:!0,isRefetching:!1}),c=()=>{let o=typeof i=="function"?i({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):i;return s(r,{...o,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await _optionalChain([o, 'optionalAccess', _37 => _37.onSuccess, 'optionalCall', _38 => _38(t)])},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await _optionalChain([o, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40(t)])},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await _optionalChain([o, 'optionalAccess', _41 => _41.onRequest, 'optionalCall', _42 => _42(t)])}})};e=Array.isArray(e)?e:[e];let u=!1;for(let o of e)o.subscribe(()=>{u?c():_nanostores.onMount.call(void 0, n,()=>(c(),u=!0,()=>{n.off(),o.off()}))});return n};function X(e){let r=_nanostores.atom.call(void 0, !1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}exports.a = $; exports.b = Q; exports.c = O; exports.d = X;
2
+ //# sourceMappingURL=chunk-6DIWT34N.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-6DIWT34N.cjs","../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts"],"names":["redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","isCredentialsSupported","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","$fetch","createFetch","getBaseURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","createProxy","target","prop","fullPath","current","segment","_","__","routePath","letter"],"mappings":"AAAA,qoBAAwC,wDAAyC,4CCArD,wCAEF,ICCbA,CAAAA,CAAiB,CAC7B,EAAA,CAAI,UAAA,CACJ,IAAA,CAAM,UAAA,CACN,KAAA,CAAO,CACN,SAAA,CAAUC,CAAAA,CAAS,iBACdA,CAAAA,mBAAQ,IAAA,6BAAM,KAAA,kBAAOA,CAAAA,qBAAQ,IAAA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,CAC5B,CAAA,CACA,KAAA,CAAO,KAAA,CAAOG,CAAAA,CAAGC,CAAAA,CAAIhB,CAAAA,CAAAA,EAAS,CAC7B,IAAMiB,CAAAA,CACL,GAAA,CACApB,CAAAA,CACE,GAAA,CAAKiB,CAAAA,EACLA,CAAAA,CAAQ,OAAA,CAAQ,QAAA,CAAWI,CAAAA,EAAW,CAAA,CAAA,EAAIA,CAAAA,CAAO,WAAA,CAAY,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-6DIWT34N.cjs","sourcesContent":[null,"import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\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\tcredentials: isCredentialsSupported ? \"include\" : \"same-origin\",\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as s,b as i,d as r}from"./chunk-DIAAB4CL.js";import{a as o}from"./chunk-C57CCQKY.js";function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=s(p),n={};for(let[a,g]of Object.entries(t))n[`use${o(a)}`]=g;let{$session:c,_sessionSignal:u}=r(e),y={...l,...n,$fetch:e,useSession:c};return i(y,e,f,{...t,_sessionSignal:u},m)}export{O as a};
2
+ //# sourceMappingURL=chunk-AAGMZIXH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/vanilla.ts"],"sourcesContent":["import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\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 BetterAuthClientPlugin\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\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"],"mappings":"8FAiCO,SAASA,EACfC,EACC,CACD,GAAM,CACL,kBAAAC,EACA,eAAAC,EACA,aAAAC,EACA,OAAAC,EACA,cAAAC,CACD,EAAIC,EAAgBN,CAAO,EACvBO,EAAqC,CAAC,EAC1C,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQN,CAAY,EACrDI,EAAc,MAAMG,EAAsBF,CAAG,CAAC,EAAE,EAAIC,EAGrD,GAAM,CAAE,SAAAE,EAAU,eAAAC,CAAe,EAAIC,EAAuBT,CAAM,EAC5DU,EAAS,CACd,GAAGZ,EACH,GAAGK,EACH,OAAAH,EACA,WAAYO,CACb,EAWA,OAVcI,EACbD,EACAV,EACAH,EACA,CACC,GAAGE,EACH,eAAAS,CACD,EACAP,CACD,CAaD","names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter","$session","_sessionSignal","getSessionAtom","routes","createDynamicPathProxy"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk5ZBXSZHEcjs = require('./chunk-5ZBXSZHE.cjs');var _chunk6YSOZOBLcjs = require('./chunk-6YSOZOBL.cjs');function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=_chunk5ZBXSZHEcjs.a.call(void 0, p),n={};for(let[a,g]of Object.entries(t))n[`use${_chunk6YSOZOBLcjs.a.call(void 0, a)}`]=g;let{$session:c,_sessionSignal:u}=_chunk5ZBXSZHEcjs.d.call(void 0, e),y={...l,...n,$fetch:e,useSession:c};return _chunk5ZBXSZHEcjs.b.call(void 0, y,e,f,{...t,_sessionSignal:u},m)}exports.a = O;
2
+ //# sourceMappingURL=chunk-AN3H7RRS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-AN3H7RRS.cjs","../src/client/vanilla.ts"],"names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter"],"mappings":"AAAA,iIAAsD,wDAAyC,SCiC/EA,CAAAA,CACfC,CAAAA,CACC,CACD,GAAM,CACL,iBAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CACD,CAAA,CAAIC,iCAAAA,CAAuB,CAAA,CACvBC,CAAAA,CAAqC,CAAC,CAAA,CAC1C,GAAA,CAAA,GAAW,CAACC,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,OAAA,CAAQN,CAAY,CAAA,CACrDI,CAAAA,CAAc,CAAA,GAAA,EAAMG,iCAAAA,CAAyB,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-AN3H7RRS.cjs","sourcesContent":[null,"import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\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 BetterAuthClientPlugin\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\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as P}from"./chunk-ZXH7J5K5.js";import{a as m}from"./chunk-GNYPEE5I.js";import{createFetch as U}from"@better-fetch/fetch";import"nanostores";import{betterFetch as L}from"@better-fetch/fetch";var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},R={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},b={id:"csrf",name:"CSRF Check",async init(e,r){if(r?.method!=="GET"){r=r||{};let s="credentials"in Request.prototype,{data:i,error:n}=await L("/csrf",{body:void 0,baseURL:r.baseURL,...s?{credentials:"include"}:{},plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(n){if(n.status===404)throw new m("CSRF 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).");if(n.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new m("Failed to fetch CSRF token: "+n.message)}let c=i?.csrfToken;r.body={...r?.body,csrfToken:c}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,s=U({baseURL:P(e?.fetchOptions?.baseURL||e?.baseURL),...r?{credentials:"include"}:{},method:"GET",...e?.fetchOptions,plugins:e?.disableDefaultFetchPlugins?e.fetchOptions?.plugins:[...e?.disableCSRFTokenCheck?[]:[b],F,R,...e?.fetchOptions?.plugins?.filter(t=>t!==void 0)||[],...e?.plugins?.flatMap(t=>t.fetchPlugins).filter(t=>t!==void 0)||[]]}),i=e?.plugins||[],n={},c={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of i)t.getActions&&Object.assign(n,t.getActions?.(s)),t.getAtoms&&Object.assign(c,t.getAtoms?.(s)),t.pathMethods&&Object.assign(u,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:c,pluginPathMethods:u,atomListeners:o,$fetch:s}};function E(e,r,s){let i=r[e],{fetchOptions:n,query:c,...u}=s||{};return i||(n?.method?n.method:u&&Object.keys(u).length>0?"POST":"GET")}function Q(e,r,s,i,n){function c(u=[]){return new Proxy(function(){},{get(o,t){let l=[...u,t],a=e;for(let d of l)if(a&&typeof a=="object"&&d in a)a=a[d];else{a=void 0;break}return typeof a=="function"?a:c(l)},apply:async(o,t,l)=>{let a="/"+u.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(a,s,d);return await r(a,{...f,body:y==="GET"?void 0:{...B,...f?.body||{}},query:A||f?.query,method:y,async onSuccess(g){await f?.onSuccess?.(g);let h=n?.find(w=>w.matcher(a));if(!h)return;let p=i[h.signal];if(!p)return;let C=p.get();setTimeout(()=>{p.set(!C)},10)}})}})}return c()}import"@better-fetch/fetch";import{atom as k,onMount as q}from"nanostores";var O=(e,r,s,i)=>{let n=k({data:null,error:null,isPending:!0,isRefetching:!1}),c=()=>{let o=typeof i=="function"?i({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):i;return s(r,{...o,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await o?.onSuccess?.(t)},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await o?.onError?.(t)},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await o?.onRequest?.(t)}})};e=Array.isArray(e)?e:[e];let u=!1;for(let o of e)o.subscribe(()=>{u?c():q(n,()=>(c(),u=!0,()=>{n.off(),o.off()}))});return n};import{atom as W}from"nanostores";function X(e){let r=W(!1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}export{$ as a,Q as b,O as c,X as d};
2
+ //# sourceMappingURL=chunk-DIAAB4CL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/query.ts","../src/client/session-atom.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\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\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n","import {\n\tBetterFetchError,\n\ttype BetterFetch,\n\ttype BetterFetchOption,\n} from \"@better-fetch/fetch\";\nimport { atom, onMount, type PreinitializedWritableAtom } from \"nanostores\";\n\nexport const useAuthQuery = <T>(\n\tinitializedAtom:\n\t\t| PreinitializedWritableAtom<any>\n\t\t| PreinitializedWritableAtom<any>[],\n\tpath: string,\n\t$fetch: BetterFetch,\n\toptions?:\n\t\t| ((value: {\n\t\t\t\tdata: null | T;\n\t\t\t\terror: null | BetterFetchError;\n\t\t\t\tisPending: boolean;\n\t\t }) => BetterFetchOption)\n\t\t| BetterFetchOption,\n) => {\n\tconst value = atom<{\n\t\tdata: null | T;\n\t\terror: null | BetterFetchError;\n\t\tisPending: boolean;\n\t\tisRefetching: boolean;\n\t}>({\n\t\tdata: null,\n\t\terror: null,\n\t\tisPending: true,\n\t\tisRefetching: false,\n\t});\n\n\tconst fn = () => {\n\t\tconst opts =\n\t\t\ttypeof options === \"function\"\n\t\t\t\t? options({\n\t\t\t\t\t\tdata: value.get().data,\n\t\t\t\t\t\terror: value.get().error,\n\t\t\t\t\t\tisPending: value.get().isPending,\n\t\t\t\t\t})\n\t\t\t\t: options;\n\t\treturn $fetch<T>(path, {\n\t\t\t...opts,\n\t\t\tonSuccess: async (context) => {\n\t\t\t\tvalue.set({\n\t\t\t\t\tdata: context.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onSuccess?.(context);\n\t\t\t},\n\t\t\tasync onError(context) {\n\t\t\t\tvalue.set({\n\t\t\t\t\terror: context.error,\n\t\t\t\t\tdata: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onError?.(context);\n\t\t\t},\n\t\t\tasync onRequest(context) {\n\t\t\t\tconst currentValue = value.get();\n\t\t\t\tvalue.set({\n\t\t\t\t\tisPending: currentValue.data === null,\n\t\t\t\t\tdata: currentValue.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisRefetching: true,\n\t\t\t\t});\n\t\t\t\tawait opts?.onRequest?.(context);\n\t\t\t},\n\t\t});\n\t};\n\n\tinitializedAtom = Array.isArray(initializedAtom)\n\t\t? initializedAtom\n\t\t: [initializedAtom];\n\tlet isMounted = false;\n\tfor (const initAtom of initializedAtom) {\n\t\tinitAtom.subscribe(() => {\n\t\t\tif (isMounted) {\n\t\t\t\tfn();\n\t\t\t} else {\n\t\t\t\tonMount(value, () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tisMounted = true;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tvalue.off();\n\t\t\t\t\t\tinitAtom.off();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\treturn value;\n};\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom } from \"nanostores\";\nimport type { Prettify } from \"../types/helper\";\nimport type {\n\tClientOptions,\n\tInferSessionFromClient,\n\tInferUserFromClient,\n} from \"./types\";\nimport { useAuthQuery } from \"./query\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\t$fetch: BetterFetch,\n) {\n\ttype UserWithAdditionalFields = InferUserFromClient<Option>;\n\ttype SessionWithAdditionalFields = InferSessionFromClient<Option>;\n\tconst $signal = atom<boolean>(false);\n\tconst session = useAuthQuery<{\n\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t}>($signal, \"/get-session\", $fetch, {\n\t\tmethod: \"GET\",\n\t});\n\treturn {\n\t\t$session: session,\n\t\t_sessionSignal: $signal,\n\t\t$Infer: {} as {\n\t\t\tSession: {\n\t\t\t\tsession: SessionWithAdditionalFields;\n\t\t\t\tuser: UserWithAdditionalFields;\n\t\t\t};\n\t\t},\n\t};\n}\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B,MAAM,QAAQA,CAAe,EAC5CA,EACA,CAACA,CAAe,EACnB,IAAIS,EAAY,GAChB,QAAWC,KAAYV,EACtBU,EAAS,UAAU,IAAM,CACpBD,EACHJ,EAAG,EAEHP,EAAQM,EAAO,KACdC,EAAG,EACHI,EAAY,GACL,IAAM,CACZL,EAAM,IAAI,EACVM,EAAS,IAAI,CACd,EACA,CAEH,CAAC,EAEF,OAAON,CACR,EC/FA,OAAS,QAAAO,MAAY,aASd,SAASC,EACfC,EACC,CAGD,IAAMC,EAAUC,EAAc,EAAK,EAOnC,MAAO,CACN,SAPeC,EAGbF,EAAS,eAAgBD,EAAQ,CACnC,OAAQ,KACT,CAAC,EAGA,eAAgBC,EAChB,OAAQ,CAAC,CAMV,CACD","names":["createFetch","betterFetch","redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","isCredentialsSupported","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","options","isCredentialsSupported","$fetch","createFetch","getBaseURL","csrfPlugin","redirectPlugin","addCurrentURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","path","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","atomListeners","createProxy","target","prop","fullPath","current","segment","_","__","routePath","letter","arg","argFetchOptions","options","context","matches","s","signal","val","atom","onMount","useAuthQuery","initializedAtom","path","$fetch","options","value","fn","opts","context","currentValue","isMounted","initAtom","atom","getSessionAtom","$fetch","$signal","atom","useAuthQuery"]}
@@ -0,0 +1,2 @@
1
+ import{a as s,b as i,d as r}from"./chunk-VVCADMPK.js";import{a as o}from"./chunk-C57CCQKY.js";function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=s(p),n={};for(let[a,g]of Object.entries(t))n[`use${o(a)}`]=g;let{$session:c,_sessionSignal:u}=r(e),y={...l,...n,$fetch:e,useSession:c};return i(y,e,f,{...t,_sessionSignal:u},m)}export{O as a};
2
+ //# sourceMappingURL=chunk-DYUTQKLN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/vanilla.ts"],"sourcesContent":["import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\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 BetterAuthClientPlugin\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\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"],"mappings":"8FAiCO,SAASA,EACfC,EACC,CACD,GAAM,CACL,kBAAAC,EACA,eAAAC,EACA,aAAAC,EACA,OAAAC,EACA,cAAAC,CACD,EAAIC,EAAgBN,CAAO,EACvBO,EAAqC,CAAC,EAC1C,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQN,CAAY,EACrDI,EAAc,MAAMG,EAAsBF,CAAG,CAAC,EAAE,EAAIC,EAGrD,GAAM,CAAE,SAAAE,EAAU,eAAAC,CAAe,EAAIC,EAAuBT,CAAM,EAC5DU,EAAS,CACd,GAAGZ,EACH,GAAGK,EACH,OAAAH,EACA,WAAYO,CACb,EAWA,OAVcI,EACbD,EACAV,EACAH,EACA,CACC,GAAGE,EACH,eAAAS,CACD,EACAP,CACD,CAaD","names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter","$session","_sessionSignal","getSessionAtom","routes","createDynamicPathProxy"]}
@@ -0,0 +1,2 @@
1
+ import{a as P}from"./chunk-ZXH7J5K5.js";import{a as m}from"./chunk-GNYPEE5I.js";import{createFetch as U}from"@better-fetch/fetch";import"nanostores";import{betterFetch as L}from"@better-fetch/fetch";var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},b={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},R={id:"csrf",name:"CSRF Check",async init(e,r){if(r?.method!=="GET"){r=r||{};let{data:i,error:s}=await L("/csrf",{body:void 0,baseURL:r.baseURL,plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(s){if(s.status===404)throw new m("CSRF 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).");if(s.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new m("Failed to fetch CSRF token: "+s.message)}let n=i?.csrfToken;r.body={...r?.body,csrfToken:n}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,i=U({baseURL:P(e?.fetchOptions?.baseURL||e?.baseURL),...r?{credentials:"include"}:{},method:"GET",...e?.fetchOptions,plugins:e?.disableDefaultFetchPlugins?e.fetchOptions?.plugins:[...e?.disableCSRFTokenCheck?[]:[R],F,b,...e?.fetchOptions?.plugins?.filter(t=>t!==void 0)||[],...e?.plugins?.flatMap(t=>t.fetchPlugins).filter(t=>t!==void 0)||[]]}),s=e?.plugins||[],n={},u={},c={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of s)t.getActions&&Object.assign(n,t.getActions?.(i)),t.getAtoms&&Object.assign(u,t.getAtoms?.(i)),t.pathMethods&&Object.assign(c,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:u,pluginPathMethods:c,atomListeners:o,$fetch:i}};function E(e,r,i){let s=r[e],{fetchOptions:n,query:u,...c}=i||{};return s||(n?.method?n.method:c&&Object.keys(c).length>0?"POST":"GET")}function Q(e,r,i,s,n){function u(c=[]){return new Proxy(function(){},{get(o,t){let l=[...c,t],a=e;for(let d of l)if(a&&typeof a=="object"&&d in a)a=a[d];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(o,t,l)=>{let a="/"+c.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(a,i,d);return await r(a,{...f,body:y==="GET"?void 0:{...B,...f?.body||{}},query:A||f?.query,method:y,async onSuccess(g){await f?.onSuccess?.(g);let h=n?.find(C=>C.matcher(a));if(!h)return;let p=s[h.signal];if(!p)return;let w=p.get();setTimeout(()=>{p.set(!w)},10)}})}})}return u()}import"@better-fetch/fetch";import{atom as k,onMount as q}from"nanostores";var O=(e,r,i,s)=>{let n=k({data:null,error:null,isPending:!0,isRefetching:!1}),u=()=>{let o=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;return i(r,{...o,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await o?.onSuccess?.(t)},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await o?.onError?.(t)},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await o?.onRequest?.(t)}})};e=Array.isArray(e)?e:[e];let c=!1;for(let o of e)o.subscribe(()=>{c?u():q(n,()=>(u(),c=!0,()=>{n.off(),o.off()}))});return n};import{atom as W}from"nanostores";function X(e){let r=W(!1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}export{$ as a,Q as b,O as c,X as d};
2
+ //# sourceMappingURL=chunk-EDQALO4N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/query.ts","../src/client/session-atom.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (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\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n","import {\n\tBetterFetchError,\n\ttype BetterFetch,\n\ttype BetterFetchOption,\n} from \"@better-fetch/fetch\";\nimport { atom, onMount, type PreinitializedWritableAtom } from \"nanostores\";\n\nexport const useAuthQuery = <T>(\n\tinitializedAtom:\n\t\t| PreinitializedWritableAtom<any>\n\t\t| PreinitializedWritableAtom<any>[],\n\tpath: string,\n\t$fetch: BetterFetch,\n\toptions?:\n\t\t| ((value: {\n\t\t\t\tdata: null | T;\n\t\t\t\terror: null | BetterFetchError;\n\t\t\t\tisPending: boolean;\n\t\t }) => BetterFetchOption)\n\t\t| BetterFetchOption,\n) => {\n\tconst value = atom<{\n\t\tdata: null | T;\n\t\terror: null | BetterFetchError;\n\t\tisPending: boolean;\n\t\tisRefetching: boolean;\n\t}>({\n\t\tdata: null,\n\t\terror: null,\n\t\tisPending: true,\n\t\tisRefetching: false,\n\t});\n\n\tconst fn = () => {\n\t\tconst opts =\n\t\t\ttypeof options === \"function\"\n\t\t\t\t? options({\n\t\t\t\t\t\tdata: value.get().data,\n\t\t\t\t\t\terror: value.get().error,\n\t\t\t\t\t\tisPending: value.get().isPending,\n\t\t\t\t\t})\n\t\t\t\t: options;\n\t\treturn $fetch<T>(path, {\n\t\t\t...opts,\n\t\t\tonSuccess: async (context) => {\n\t\t\t\tvalue.set({\n\t\t\t\t\tdata: context.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onSuccess?.(context);\n\t\t\t},\n\t\t\tasync onError(context) {\n\t\t\t\tvalue.set({\n\t\t\t\t\terror: context.error,\n\t\t\t\t\tdata: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onError?.(context);\n\t\t\t},\n\t\t\tasync onRequest(context) {\n\t\t\t\tconst currentValue = value.get();\n\t\t\t\tvalue.set({\n\t\t\t\t\tisPending: currentValue.data === null,\n\t\t\t\t\tdata: currentValue.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisRefetching: true,\n\t\t\t\t});\n\t\t\t\tawait opts?.onRequest?.(context);\n\t\t\t},\n\t\t});\n\t};\n\n\tinitializedAtom = Array.isArray(initializedAtom)\n\t\t? initializedAtom\n\t\t: [initializedAtom];\n\tlet isMounted = false;\n\tfor (const initAtom of initializedAtom) {\n\t\tinitAtom.subscribe(() => {\n\t\t\tif (isMounted) {\n\t\t\t\tfn();\n\t\t\t} else {\n\t\t\t\tonMount(value, () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tisMounted = true;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tvalue.off();\n\t\t\t\t\t\tinitAtom.off();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\treturn value;\n};\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom } from \"nanostores\";\nimport type { Prettify } from \"../types/helper\";\nimport type {\n\tClientOptions,\n\tInferSessionFromClient,\n\tInferUserFromClient,\n} from \"./types\";\nimport { useAuthQuery } from \"./query\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\t$fetch: BetterFetch,\n) {\n\ttype UserWithAdditionalFields = InferUserFromClient<Option>;\n\ttype SessionWithAdditionalFields = InferSessionFromClient<Option>;\n\tconst $signal = atom<boolean>(false);\n\tconst session = useAuthQuery<{\n\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t}>($signal, \"/get-session\", $fetch, {\n\t\tmethod: \"GET\",\n\t});\n\treturn {\n\t\t$session: session,\n\t\t_sessionSignal: $signal,\n\t\t$Infer: {} as {\n\t\t\tSession: {\n\t\t\t\tsession: SessionWithAdditionalFields;\n\t\t\t\tuser: UserWithAdditionalFields;\n\t\t\t};\n\t\t},\n\t};\n}\n"],"mappings":"gFAAA,OAAS,eAAAA,MAAmB,sBAE5B,MAA0B,aCF1B,OAAiC,eAAAC,MAAmB,sBAG7C,IAAMC,EAAiB,CAC7B,GAAI,WACJ,KAAM,WACN,MAAO,CACN,UAAUC,EAAS,CACdA,EAAQ,MAAM,KAAOA,EAAQ,MAAM,UAClC,OAAO,OAAW,MACrB,OAAO,SAAS,KAAOA,EAAQ,KAAK,IAGvC,CACD,CACD,EAEaC,EAAgB,CAC5B,GAAI,kBACJ,KAAM,kBACN,MAAO,CACN,UAAUD,EAAS,CAClB,GAAI,OAAO,OAAW,IAAa,CAClC,IAAME,EAAM,IAAI,IAAIF,EAAQ,GAAG,EAC/BE,EAAI,aAAa,IAAI,aAAc,OAAO,SAAS,IAAI,EACvDF,EAAQ,IAAME,CACf,CACA,OAAOF,CACR,CACD,CACD,EAEaG,EAAa,CACzB,GAAI,OACJ,KAAM,aACN,MAAM,KAAKD,EAAKE,EAAS,CACxB,GAAIA,GAAS,SAAW,MAAO,CAC9BA,EAAUA,GAAW,CAAC,EACtB,GAAM,CAAE,KAAAC,EA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M,IAAI,CACT,KAAMG,EAAQ,KACd,MAAO,KACP,UAAW,GACX,aAAc,EACf,CAAC,EACD,MAAMD,GAAM,YAAYC,CAAO,CAChC,EACA,MAAM,QAAQA,EAAS,CACtBH,EAAM,IAAI,CACT,MAAOG,EAAQ,MACf,KAAM,KACN,UAAW,GACX,aAAc,EACf,CAAC,EACD,MAAMD,GAAM,UAAUC,CAAO,CAC9B,EACA,MAAM,UAAUA,EAAS,CACxB,IAAMC,EAAeJ,EAAM,IAAI,EAC/BA,EAAM,IAAI,CACT,UAAWI,EAAa,OAAS,KACjC,KAAMA,EAAa,KACnB,MAAO,KACP,aAAc,EACf,CAAC,EACD,MAAMF,GAAM,YAAYC,CAAO,CAChC,CACD,CAAC,CACF,EAEAP,EAAkB,MAAM,QAAQA,CAAe,EAC5CA,EACA,CAACA,CAAe,EACnB,IAAIS,EAAY,GAChB,QAAWC,KAAYV,EACtBU,EAAS,UAAU,IAAM,CACpBD,EACHJ,EAAG,EAEHP,EAAQM,EAAO,KACdC,EAAG,EACHI,EAAY,GACL,IAAM,CACZL,EAAM,IAAI,EACVM,EAAS,IAAI,CACd,EACA,CAEH,CAAC,EAEF,OAAON,CACR,EC/FA,OAAS,QAAAO,MAAY,aASd,SAASC,EACfC,EACC,CAGD,IAAMC,EAAUC,EAAc,EAAK,EAOnC,MAAO,CACN,SAPeC,EAGbF,EAAS,eAAgBD,EAAQ,CACnC,OAAQ,KACT,CAAC,EAGA,eAAgBC,EAChB,OAAQ,CAAC,CAMV,CACD","names":["createFetch","betterFetch","redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","options","isCredentialsSupported","$fetch","createFetch","getBaseURL","csrfPlugin","redirectPlugin","addCurrentURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","path","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","atomListeners","createProxy","target","prop","fullPath","current","segment","_","__","routePath","letter","arg","argFetchOptions","options","context","matches","s","signal","val","atom","onMount","useAuthQuery","initializedAtom","path","$fetch","options","value","fn","opts","context","currentValue","isMounted","initAtom","atom","getSessionAtom","$fetch","$signal","atom","useAuthQuery"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6DIWT34Ncjs = require('./chunk-6DIWT34N.cjs');var _chunk6YSOZOBLcjs = require('./chunk-6YSOZOBL.cjs');function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=_chunk6DIWT34Ncjs.a.call(void 0, p),n={};for(let[a,g]of Object.entries(t))n[`use${_chunk6YSOZOBLcjs.a.call(void 0, a)}`]=g;let{$session:c,_sessionSignal:u}=_chunk6DIWT34Ncjs.d.call(void 0, e),y={...l,...n,$fetch:e,useSession:c};return _chunk6DIWT34Ncjs.b.call(void 0, y,e,f,{...t,_sessionSignal:u},m)}exports.a = O;
2
+ //# sourceMappingURL=chunk-EK3FTHVF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EK3FTHVF.cjs","../src/client/vanilla.ts"],"names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter"],"mappings":"AAAA,iIAAsD,wDAAyC,SCiC/EA,CAAAA,CACfC,CAAAA,CACC,CACD,GAAM,CACL,iBAAA,CAAAC,CAAAA,CACA,cAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CACD,CAAA,CAAIC,iCAAAA,CAAuB,CAAA,CACvBC,CAAAA,CAAqC,CAAC,CAAA,CAC1C,GAAA,CAAA,GAAW,CAACC,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,OAAA,CAAQN,CAAY,CAAA,CACrDI,CAAAA,CAAc,CAAA,GAAA,EAAMG,iCAAAA,CAAyB,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EK3FTHVF.cjs","sourcesContent":[null,"import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\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 BetterAuthClientPlugin\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\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk6DIWT34Ncjs = require('./chunk-6DIWT34N.cjs');var m=(e={redirect:!0,twoFactorPage:"/"})=>({id:"two-factor",$InferServerPlugin:{},atomListeners:[{matcher:t=>t.startsWith("/two-factor/"),signal:"_sessionSignal"}],pathMethods:{"/two-factor/disable":"POST","/two-factor/enable":"POST","/two-factor/send-otp":"POST","/two-factor/generate-backup-codes":"POST"},fetchPlugins:[{id:"two-factor",name:"two-factor",hooks:{async onSuccess(t){_optionalChain([t, 'access', _ => _.data, 'optionalAccess', _2 => _2.twoFactorRedirect])&&(e.redirect||e.twoFactorPage)&&typeof window<"u"&&(window.location.href=e.twoFactorPage)}}}]});var _browser = require('@simplewebauthn/browser');var _nanostores = require('nanostores');var f=(e,{_listPasskeys:t})=>({signIn:{passkey:async(r,i)=>{let a=await e("/passkey/generate-authenticate-options",{method:"POST",body:{email:_optionalChain([r, 'optionalAccess', _3 => _3.email])}});if(!a.data)return a;try{let s=await _browser.startAuthentication.call(void 0, a.data,_optionalChain([r, 'optionalAccess', _4 => _4.autoFill])||!1),o=await e("/passkey/verify-authentication",{body:{response:s},..._optionalChain([r, 'optionalAccess', _5 => _5.fetchOptions]),...i,method:"POST"});if(!o.data)return o}catch(s){console.log(s)}}},passkey:{addPasskey:async(r,i)=>{let a=await e("/passkey/generate-register-options",{method:"GET"});if(!a.data)return a;try{let s=await _browser.startRegistration.call(void 0, a.data),o=await e("/passkey/verify-registration",{..._optionalChain([r, 'optionalAccess', _6 => _6.fetchOptions]),...i,body:{response:s,name:_optionalChain([r, 'optionalAccess', _7 => _7.name])},method:"POST"});if(!o.data)return o;t.set(Math.random())}catch(s){return s instanceof _browser.WebAuthnError?s.code==="ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED"?{data:null,error:{message:"previously registered",status:400,statusText:"BAD_REQUEST"}}:s.code==="ERROR_CEREMONY_ABORTED"?{data:null,error:{message:"registration cancelled",status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s.message,status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:s instanceof Error?s.message:"unknown error",status:500,statusText:"INTERNAL_SERVER_ERROR"}}}}},$Infer:{}}),O= exports.c =()=>{let e=_nanostores.atom.call(void 0, );return{id:"passkey",$InferServerPlugin:{},getActions:t=>f(t,{_listPasskeys:e}),getAtoms(t){return{listPasskeys:_chunk6DIWT34Ncjs.c.call(void 0, e,"/passkey/list-user-passkeys",t,{method:"GET",credentials:"include"}),_listPasskeys:e}},pathMethods:{"/passkey/register":"POST","/passkey/authenticate":"POST"},atomListeners:[{matcher(t){return t==="/passkey/verify-registration"||t==="/passkey/delete-passkey"},signal:"_listPasskeys"}]}};exports.a = m; exports.b = f; exports.c = O;
2
+ //# sourceMappingURL=chunk-EP6HCSMM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EP6HCSMM.cjs","../src/plugins/two-factor/client.ts","../src/plugins/passkey/client.ts"],"names":["twoFactorClient","options","path","context","getPasskeyActions","$fetch","_listPasskeys","opts","response","res","startAuthentication","verified","e","fetchOpts","startRegistration","WebAuthnError","passkeyClient","atom","useAuthQuery"],"mappings":"AAAA,qoBAAwC,ICG3BA,CAAAA,CAAkB,CAC9BC,CAAAA,CAQI,CACH,QAAA,CAAU,CAAA,CAAA,CACV,aAAA,CAAe,GAChB,CAAA,CAAA,EAAA,CAEO,CACN,EAAA,CAAI,YAAA,CACJ,kBAAA,CAAoB,CAAC,CAAA,CACrB,aAAA,CAAe,CACd,CACC,OAAA,CAAUC,CAAAA,EAASA,CAAAA,CAAK,UAAA,CAAW,cAAc,CAAA,CACjD,MAAA,CAAQ,gBACT,CACD,CAAA,CACA,WAAA,CAAa,CACZ,qBAAA,CAAuB,MAAA,CACvB,oBAAA,CAAsB,MAAA,CACtB,sBAAA,CAAwB,MAAA,CACxB,mCAAA,CAAqC,MACtC,CAAA,CACA,YAAA,CAAc,CACb,CACC,EAAA,CAAI,YAAA,CACJ,IAAA,CAAM,YAAA,CACN,KAAA,CAAO,CACN,MAAM,SAAA,CAAUC,CAAAA,CAAS,iBACpBA,CAAAA,mBAAQ,IAAA,6BAAM,mBAAA,EAAA,CACbF,CAAAA,CAAQ,QAAA,EAAYA,CAAAA,CAAQ,aAAA,CAAA,EAC3B,OAAO,MAAA,CAAW,GAAA,EAAA,CACrB,MAAA,CAAO,QAAA,CAAS,IAAA,CAAOA,CAAAA,CAAQ,aAAA,CAInC,CACD,CACD,CACD,CACD,CAAA,CAAA,CChDD,kDAIO,wCAUc,IAERG,CAAAA,CAAoB,CAChCC,CAAAA,CACA,CACC,aAAA,CAAAC,CACD,CAAA,CAAA,EAAA,CA+HO,CACN,MAAA,CAAQ,CAIP,OAAA,CAhIoB,KAAA,CACrBC,CAAAA,CAKAN,CAAAA,C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CAAAA,CACpBZ,CACA,6BAAA,CACAD,CAAAA,CACA,CACC,MAAA,CAAQ,KAAA,CACR,WAAA,CAAa,SACd,CACD,CAAA,CAGC,aAAA,CAAAC,CACD,CACD,CAAA,CACA,WAAA,CAAa,CACZ,mBAAA,CAAqB,MAAA,CACrB,uBAAA,CAAyB,MAC1B,CAAA,CACA,aAAA,CAAe,CACd,CACC,OAAA,CAAQJ,CAAAA,CAAM,CACb,OACCA,CAAAA,GAAS,8BAAA,EACTA,CAAAA,GAAS,yBAEX,CAAA,CACA,MAAA,CAAQ,eACT,CACD,CACD,CACD,CAAA,CAAA,4CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EP6HCSMM.cjs","sourcesContent":[null,"import type { BetterAuthClientPlugin } from \"../../client/types\";\nimport type { twoFactor as twoFa } from \"../../plugins/two-factor\";\n\nexport const twoFactorClient = (\n\toptions: {\n\t\ttwoFactorPage: string;\n\t\t/**\n\t\t * Redirect to the two factor page. If twoFactorPage\n\t\t * is not set this will redirect to the root path.\n\t\t * @default true\n\t\t */\n\t\tredirect?: boolean;\n\t} = {\n\t\tredirect: true,\n\t\ttwoFactorPage: \"/\",\n\t},\n) => {\n\treturn {\n\t\tid: \"two-factor\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof twoFa>,\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher: (path) => path.startsWith(\"/two-factor/\"),\n\t\t\t\tsignal: \"_sessionSignal\",\n\t\t\t},\n\t\t],\n\t\tpathMethods: {\n\t\t\t\"/two-factor/disable\": \"POST\",\n\t\t\t\"/two-factor/enable\": \"POST\",\n\t\t\t\"/two-factor/send-otp\": \"POST\",\n\t\t\t\"/two-factor/generate-backup-codes\": \"POST\",\n\t\t},\n\t\tfetchPlugins: [\n\t\t\t{\n\t\t\t\tid: \"two-factor\",\n\t\t\t\tname: \"two-factor\",\n\t\t\t\thooks: {\n\t\t\t\t\tasync onSuccess(context) {\n\t\t\t\t\t\tif (context.data?.twoFactorRedirect) {\n\t\t\t\t\t\t\tif (options.redirect || options.twoFactorPage) {\n\t\t\t\t\t\t\t\tif (typeof window !== \"undefined\") {\n\t\t\t\t\t\t\t\t\twindow.location.href = options.twoFactorPage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n","import type { BetterFetch, BetterFetchOption } from \"@better-fetch/fetch\";\nimport {\n\tWebAuthnError,\n\tstartAuthentication,\n\tstartRegistration,\n} from \"@simplewebauthn/browser\";\nimport type {\n\tPublicKeyCredentialCreationOptionsJSON,\n\tPublicKeyCredentialRequestOptionsJSON,\n} from \"@simplewebauthn/types\";\nimport type { Session } from \"inspector\";\nimport type { User } from \"../../db/schema\";\nimport type { passkey as passkeyPl, Passkey } from \"../../plugins\";\nimport type { BetterAuthClientPlugin } from \"../../client/types\";\nimport { useAuthQuery } from \"../../client\";\nimport { atom } from \"nanostores\";\n\nexport const getPasskeyActions = (\n\t$fetch: BetterFetch,\n\t{\n\t\t_listPasskeys,\n\t}: {\n\t\t_listPasskeys: ReturnType<typeof atom<any>>;\n\t},\n) => {\n\tconst signInPasskey = async (\n\t\topts?: {\n\t\t\tautoFill?: boolean;\n\t\t\temail?: string;\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t},\n\t\toptions?: BetterFetchOption,\n\t) => {\n\t\tconst response = await $fetch<PublicKeyCredentialRequestOptionsJSON>(\n\t\t\t\"/passkey/generate-authenticate-options\",\n\t\t\t{\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody: {\n\t\t\t\t\temail: opts?.email,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (!response.data) {\n\t\t\treturn response;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startAuthentication(\n\t\t\t\tresponse.data,\n\t\t\t\topts?.autoFill || false,\n\t\t\t);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tsession: Session;\n\t\t\t\tuser: User;\n\t\t\t}>(\"/passkey/verify-authentication\", {\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t},\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...options,\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconsole.log(e);\n\t\t}\n\t};\n\n\tconst registerPasskey = async (\n\t\topts?: {\n\t\t\tfetchOptions?: BetterFetchOption;\n\t\t\t/**\n\t\t\t * The name of the passkey. This is used to\n\t\t\t * identify the passkey in the UI.\n\t\t\t */\n\t\t\tname?: string;\n\t\t},\n\t\tfetchOpts?: BetterFetchOption,\n\t) => {\n\t\tconst options = await $fetch<PublicKeyCredentialCreationOptionsJSON>(\n\t\t\t\"/passkey/generate-register-options\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t},\n\t\t);\n\t\tif (!options.data) {\n\t\t\treturn options;\n\t\t}\n\t\ttry {\n\t\t\tconst res = await startRegistration(options.data);\n\t\t\tconst verified = await $fetch<{\n\t\t\t\tpasskey: Passkey;\n\t\t\t}>(\"/passkey/verify-registration\", {\n\t\t\t\t...opts?.fetchOptions,\n\t\t\t\t...fetchOpts,\n\t\t\t\tbody: {\n\t\t\t\t\tresponse: res,\n\t\t\t\t\tname: opts?.name,\n\t\t\t\t},\n\t\t\t\tmethod: \"POST\",\n\t\t\t});\n\t\t\tif (!verified.data) {\n\t\t\t\treturn verified;\n\t\t\t}\n\t\t\t_listPasskeys.set(Math.random());\n\t\t} catch (e) {\n\t\t\tif (e instanceof WebAuthnError) {\n\t\t\t\tif (e.code === \"ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"previously registered\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (e.code === \"ERROR_CEREMONY_ABORTED\") {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: null,\n\t\t\t\t\t\terror: {\n\t\t\t\t\t\t\tmessage: \"registration cancelled\",\n\t\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\tstatus: 400,\n\t\t\t\t\t\tstatusText: \"BAD_REQUEST\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdata: null,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: e instanceof Error ? e.message : \"unknown error\",\n\t\t\t\t\tstatus: 500,\n\t\t\t\t\tstatusText: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t};\n\n\treturn {\n\t\tsignIn: {\n\t\t\t/**\n\t\t\t * Sign in with a registered passkey\n\t\t\t */\n\t\t\tpasskey: signInPasskey,\n\t\t},\n\t\tpasskey: {\n\t\t\t/**\n\t\t\t * Add a passkey to the user account\n\t\t\t */\n\t\t\taddPasskey: registerPasskey,\n\t\t},\n\t\t/**\n\t\t * Inferred Internal Types\n\t\t */\n\t\t$Infer: {} as {\n\t\t\tPasskey: Passkey;\n\t\t},\n\t};\n};\n\nexport const passkeyClient = () => {\n\tconst _listPasskeys = atom<any>();\n\treturn {\n\t\tid: \"passkey\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof passkeyPl>,\n\t\tgetActions: ($fetch) =>\n\t\t\tgetPasskeyActions($fetch, {\n\t\t\t\t_listPasskeys,\n\t\t\t}),\n\t\tgetAtoms($fetch) {\n\t\t\tconst listPasskeys = useAuthQuery<Passkey[]>(\n\t\t\t\t_listPasskeys,\n\t\t\t\t\"/passkey/list-user-passkeys\",\n\t\t\t\t$fetch,\n\t\t\t\t{\n\t\t\t\t\tmethod: \"GET\",\n\t\t\t\t\tcredentials: \"include\",\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tlistPasskeys,\n\t\t\t\t_listPasskeys,\n\t\t\t};\n\t\t},\n\t\tpathMethods: {\n\t\t\t\"/passkey/register\": \"POST\",\n\t\t\t\"/passkey/authenticate\": \"POST\",\n\t\t},\n\t\tatomListeners: [\n\t\t\t{\n\t\t\t\tmatcher(path) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\tpath === \"/passkey/verify-registration\" ||\n\t\t\t\t\t\tpath === \"/passkey/delete-passkey\"\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tsignal: \"_listPasskeys\",\n\t\t\t},\n\t\t],\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkH5ZHLIW4cjs = require('./chunk-H5ZHLIW4.cjs');var _chunkWNGZ4EQPcjs = require('./chunk-WNGZ4EQP.cjs');var _fetch = require('@better-fetch/fetch');var _nanostores = require('nanostores');var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){_optionalChain([e, 'access', _ => _.data, 'optionalAccess', _2 => _2.url])&&_optionalChain([e, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.redirect])&&typeof window<"u"&&(window.location.href=e.data.url)}}},R={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},b={id:"csrf",name:"CSRF Check",async init(e,r){if(_optionalChain([r, 'optionalAccess', _5 => _5.method])!=="GET"){r=r||{};let s="credentials"in Request.prototype,{data:i,error:n}=await _fetch.betterFetch.call(void 0, "/csrf",{body:void 0,baseURL:r.baseURL,...s?{credentials:"include"}:{},plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(n){if(n.status===404)throw new (0, _chunkWNGZ4EQPcjs.a)("CSRF 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).");if(n.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new (0, _chunkWNGZ4EQPcjs.a)("Failed to fetch CSRF token: "+n.message)}let c=_optionalChain([i, 'optionalAccess', _6 => _6.csrfToken]);r.body={..._optionalChain([r, 'optionalAccess', _7 => _7.body]),csrfToken:c}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,s=_fetch.createFetch.call(void 0, {baseURL:_chunkH5ZHLIW4cjs.a.call(void 0, _optionalChain([e, 'optionalAccess', _8 => _8.fetchOptions, 'optionalAccess', _9 => _9.baseURL])||_optionalChain([e, 'optionalAccess', _10 => _10.baseURL])),...r?{credentials:"include"}:{},method:"GET",..._optionalChain([e, 'optionalAccess', _11 => _11.fetchOptions]),plugins:_optionalChain([e, 'optionalAccess', _12 => _12.disableDefaultFetchPlugins])?_optionalChain([e, 'access', _13 => _13.fetchOptions, 'optionalAccess', _14 => _14.plugins]):[..._optionalChain([e, 'optionalAccess', _15 => _15.disableCSRFTokenCheck])?[]:[b],F,R,..._optionalChain([e, 'optionalAccess', _16 => _16.fetchOptions, 'optionalAccess', _17 => _17.plugins, 'optionalAccess', _18 => _18.filter, 'call', _19 => _19(t=>t!==void 0)])||[],..._optionalChain([e, 'optionalAccess', _20 => _20.plugins, 'optionalAccess', _21 => _21.flatMap, 'call', _22 => _22(t=>t.fetchPlugins), 'access', _23 => _23.filter, 'call', _24 => _24(t=>t!==void 0)])||[]]}),i=_optionalChain([e, 'optionalAccess', _25 => _25.plugins])||[],n={},c={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of i)t.getActions&&Object.assign(n,_optionalChain([t, 'access', _26 => _26.getActions, 'optionalCall', _27 => _27(s)])),t.getAtoms&&Object.assign(c,_optionalChain([t, 'access', _28 => _28.getAtoms, 'optionalCall', _29 => _29(s)])),t.pathMethods&&Object.assign(u,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:c,pluginPathMethods:u,atomListeners:o,$fetch:s}};function E(e,r,s){let i=r[e],{fetchOptions:n,query:c,...u}=s||{};return i||(_optionalChain([n, 'optionalAccess', _30 => _30.method])?n.method:u&&Object.keys(u).length>0?"POST":"GET")}function Q(e,r,s,i,n){function c(u=[]){return new Proxy(function(){},{get(o,t){let l=[...u,t],a=e;for(let d of l)if(a&&typeof a=="object"&&d in a)a=a[d];else{a=void 0;break}return typeof a=="function"?a:c(l)},apply:async(o,t,l)=>{let a="/"+u.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(a,s,d);return await r(a,{...f,body:y==="GET"?void 0:{...B,..._optionalChain([f, 'optionalAccess', _31 => _31.body])||{}},query:A||_optionalChain([f, 'optionalAccess', _32 => _32.query]),method:y,async onSuccess(g){await _optionalChain([f, 'optionalAccess', _33 => _33.onSuccess, 'optionalCall', _34 => _34(g)]);let h=_optionalChain([n, 'optionalAccess', _35 => _35.find, 'call', _36 => _36(w=>w.matcher(a))]);if(!h)return;let p=i[h.signal];if(!p)return;let C=p.get();setTimeout(()=>{p.set(!C)},10)}})}})}return c()}var O=(e,r,s,i)=>{let n=_nanostores.atom.call(void 0, {data:null,error:null,isPending:!0,isRefetching:!1}),c=()=>{let o=typeof i=="function"?i({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):i;return s(r,{...o,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await _optionalChain([o, 'optionalAccess', _37 => _37.onSuccess, 'optionalCall', _38 => _38(t)])},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await _optionalChain([o, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40(t)])},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await _optionalChain([o, 'optionalAccess', _41 => _41.onRequest, 'optionalCall', _42 => _42(t)])}})};e=Array.isArray(e)?e:[e];let u=!1;for(let o of e)o.subscribe(()=>{u?c():_nanostores.onMount.call(void 0, n,()=>(c(),u=!0,()=>{n.off(),o.off()}))});return n};function X(e){let r=_nanostores.atom.call(void 0, !1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}exports.a = $; exports.b = Q; exports.c = O; exports.d = X;
2
+ //# sourceMappingURL=chunk-EWV4YOZZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EWV4YOZZ.cjs","../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts"],"names":["redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","isCredentialsSupported","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","$fetch","createFetch","getBaseURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","createProxy","target","pr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,EAAAA,GAAWF,CAAAA,CACrB,EAAA,CAAIC,CAAAA,EAAW,OAAOA,CAAAA,EAAY,QAAA,EAAYC,EAAAA,GAAWD,CAAAA,CACxDA,CAAAA,CAAUA,CAAAA,CAAQC,CAAO,CAAA,CAAA,IACnB,CACND,CAAAA,CAAU,KAAA,CAAA,CACV,KACD,CAED,OAAI,OAAOA,CAAAA,EAAY,UAAA,CACfA,CAAAA,CAEDJ,CAAAA,CAAYG,CAAQ,CAC5B,CAAA,CACA,KAAA,CAAO,KAAA,CAAOG,CAAAA,CAAGC,CAAAA,CAAIhB,CAAAA,CAAAA,EAAS,CAC7B,IAAMiB,CAAAA,CACL,GAAA,CACApB,CAAAA,CACE,GAAA,CAAKiB,CAAAA,EACLA,CAAAA,CAAQ,OAAA,CAAQ,QAAA,CAAWI,CAAAA,EAAW,CAAA,CAAA,EAAIA,CAAAA,CAAO,WAAA,CAAY,CAAC,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-EWV4YOZZ.cjs","sourcesContent":[null,"import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\t\t\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\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\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\t\t\tplugins: [],\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as P}from"./chunk-ZXH7J5K5.js";import{a as m}from"./chunk-GNYPEE5I.js";import{createFetch as U}from"@better-fetch/fetch";import"nanostores";import{betterFetch as L}from"@better-fetch/fetch";var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},b={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},R={id:"csrf",name:"CSRF Check",async init(e,r){if(r?.method!=="GET"){r=r||{};let{data:i,error:s}=await L("/csrf",{body:void 0,baseURL:r.baseURL,plugins:[],method:"GET",customFetchImpl:r.customFetchImpl});if(s){if(s.status===404)throw new m("CSRF 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).");if(s.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new m("Failed to fetch CSRF token: "+s.message)}let n=i?.csrfToken;r.body={...r?.body,csrfToken:n}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r="credentials"in Request.prototype,i=U({baseURL:P(e?.fetchOptions?.baseURL||e?.baseURL),...r?{credentials:"include"}:{},method:"GET",...e?.fetchOptions,plugins:e?.disableDefaultFetchPlugins?e.fetchOptions?.plugins:[...e?.disableCSRFTokenCheck?[]:[R],F,b,...e?.fetchOptions?.plugins?.filter(t=>t!==void 0)||[],...e?.plugins?.flatMap(t=>t.fetchPlugins).filter(t=>t!==void 0)||[]]}),s=e?.plugins||[],n={},u={},c={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of s)t.getActions&&Object.assign(n,t.getActions?.(i)),t.getAtoms&&Object.assign(u,t.getAtoms?.(i)),t.pathMethods&&Object.assign(c,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:n,pluginsAtoms:u,pluginPathMethods:c,atomListeners:o,$fetch:i}};function E(e,r,i){let s=r[e],{fetchOptions:n,query:u,...c}=i||{};return s||(n?.method?n.method:c&&Object.keys(c).length>0?"POST":"GET")}function Q(e,r,i,s,n){function u(c=[]){return new Proxy(function(){},{get(o,t){let l=[...c,t],a=e;for(let d of l)if(a&&typeof a=="object"&&d in a)a=a[d];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(o,t,l)=>{let a="/"+c.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),d=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=d,f={...T,...S},y=E(a,i,d);return await r(a,{...f,body:y==="GET"?void 0:{...B,...f?.body||{}},query:A||f?.query,method:y,async onSuccess(g){await f?.onSuccess?.(g);let h=n?.find(C=>C.matcher(a));if(!h)return;let p=s[h.signal];if(!p)return;let w=p.get();setTimeout(()=>{p.set(!w)},10)}})}})}return u()}import"@better-fetch/fetch";import{atom as k,onMount as q}from"nanostores";var O=(e,r,i,s)=>{let n=k({data:null,error:null,isPending:!0,isRefetching:!1}),u=()=>{let o=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;return i(r,{...o,onSuccess:async t=>{n.set({data:t.data,error:null,isPending:!1,isRefetching:!1}),await o?.onSuccess?.(t)},async onError(t){n.set({error:t.error,data:null,isPending:!1,isRefetching:!1}),await o?.onError?.(t)},async onRequest(t){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await o?.onRequest?.(t)}})};e=Array.isArray(e)?e:[e];let c=!1;for(let o of e)o.subscribe(()=>{c?u():q(n,()=>(u(),c=!0,()=>{n.off(),o.off()}))});return n};import{atom as W}from"nanostores";function X(e){let r=W(!1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}export{$ as a,Q as b,O as c,X as d};
2
+ //# sourceMappingURL=chunk-F23RL5RN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/config.ts","../src/client/fetch-plugins.ts","../src/client/proxy.ts","../src/client/query.ts","../src/client/session-atom.ts"],"sourcesContent":["import { createFetch } from \"@better-fetch/fetch\";\nimport { getBaseURL } from \"../utils/url\";\nimport { type Atom } from \"nanostores\";\nimport type { AtomListener, ClientOptions } from \"./types\";\nimport { addCurrentURL, csrfPlugin, redirectPlugin } from \"./fetch-plugins\";\n\nexport const getClientConfig = <O extends ClientOptions>(options?: O) => {\n\tconst isCredentialsSupported = \"credentials\" in Request.prototype;\n\tconst $fetch = createFetch({\n\t\tbaseURL: getBaseURL(options?.fetchOptions?.baseURL || options?.baseURL),\n\t\t...(isCredentialsSupported ? { credentials: \"include\" } : {}),\n\t\tmethod: \"GET\",\n\t\t...options?.fetchOptions,\n\t\tplugins: options?.disableDefaultFetchPlugins\n\t\t\t? options.fetchOptions?.plugins\n\t\t\t: [\n\t\t\t\t\t...(!options?.disableCSRFTokenCheck ? [csrfPlugin] : []),\n\t\t\t\t\tredirectPlugin,\n\t\t\t\t\taddCurrentURL,\n\t\t\t\t\t...(options?.fetchOptions?.plugins?.filter(\n\t\t\t\t\t\t(pl) => pl !== undefined,\n\t\t\t\t\t) || []),\n\t\t\t\t\t...(options?.plugins\n\t\t\t\t\t\t?.flatMap((plugin) => plugin.fetchPlugins)\n\t\t\t\t\t\t.filter((pl) => pl !== undefined) || []),\n\t\t\t\t],\n\t});\n\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\t\"/user/revoke-sessions\": \"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 (\n\t\t\t\t\tpath === \"/sign-out\" ||\n\t\t\t\t\tpath === \"/user/update\" ||\n\t\t\t\t\tpath.startsWith(\"/sign-in\") ||\n\t\t\t\t\tpath.startsWith(\"/sign-up\")\n\t\t\t\t);\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","import { type BetterFetchPlugin, betterFetch } from \"@better-fetch/fetch\";\nimport { BetterAuthError } from \"../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 (options?.method !== \"GET\") {\n\t\t\toptions = options || {};\n\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\tcustomFetchImpl: options.customFetchImpl,\n\t\t\t});\n\t\t\tif (error) {\n\t\t\t\tif (error.status === 404) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t\"CSRF 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\t);\n\t\t\t\t}\n\n\t\t\t\tif (error.status === 429) {\n\t\t\t\t\treturn new Response(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tmessage: \"Too many requests. Please try again later.\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 429,\n\t\t\t\t\t\t\tstatusText: \"Too Many Requests\",\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\"Failed to fetch CSRF token: \" + error.message,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst csrfToken = data?.csrfToken;\n\t\t\toptions.body = {\n\t\t\t\t...options?.body,\n\t\t\t\tcsrfToken: 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, BetterFetchOption } from \"@better-fetch/fetch\";\nimport type { Atom, PreinitializedWritableAtom } from \"nanostores\";\nimport type { ProxyRequest } from \"./path-to-object\";\nimport type { BetterAuthClientPlugin } from \"./types\";\n\nfunction getMethod(\n\tpath: string,\n\tknownPathMethods: Record<string, \"POST\" | \"GET\">,\n\targs:\n\t\t| { fetchOptions?: BetterFetchOption; query?: Record<string, any> }\n\t\t| undefined,\n) {\n\tconst method = knownPathMethods[path];\n\tconst { fetchOptions, query, ...body } = args || {};\n\tif (method) {\n\t\treturn method;\n\t}\n\tif (fetchOptions?.method) {\n\t\treturn fetchOptions.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: BetterAuthClientPlugin[\"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\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\t\t\t\tconst arg = (args[0] || {}) as ProxyRequest;\n\t\t\t\tconst fetchOptions = (args[1] || {}) as BetterFetchOption;\n\t\t\t\tconst { query, fetchOptions: argFetchOptions, ...body } = arg;\n\t\t\t\tconst options = {\n\t\t\t\t\t...fetchOptions,\n\t\t\t\t\t...argFetchOptions,\n\t\t\t\t};\n\t\t\t\tconst method = getMethod(routePath, knownPathMethods, 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 || options?.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 as any];\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\tconst val = signal.get();\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(!val);\n\t\t\t\t\t\t}, 10);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t}\n\treturn createProxy() as T;\n}\n","import {\n\tBetterFetchError,\n\ttype BetterFetch,\n\ttype BetterFetchOption,\n} from \"@better-fetch/fetch\";\nimport { atom, onMount, type PreinitializedWritableAtom } from \"nanostores\";\n\nexport const useAuthQuery = <T>(\n\tinitializedAtom:\n\t\t| PreinitializedWritableAtom<any>\n\t\t| PreinitializedWritableAtom<any>[],\n\tpath: string,\n\t$fetch: BetterFetch,\n\toptions?:\n\t\t| ((value: {\n\t\t\t\tdata: null | T;\n\t\t\t\terror: null | BetterFetchError;\n\t\t\t\tisPending: boolean;\n\t\t }) => BetterFetchOption)\n\t\t| BetterFetchOption,\n) => {\n\tconst value = atom<{\n\t\tdata: null | T;\n\t\terror: null | BetterFetchError;\n\t\tisPending: boolean;\n\t\tisRefetching: boolean;\n\t}>({\n\t\tdata: null,\n\t\terror: null,\n\t\tisPending: true,\n\t\tisRefetching: false,\n\t});\n\n\tconst fn = () => {\n\t\tconst opts =\n\t\t\ttypeof options === \"function\"\n\t\t\t\t? options({\n\t\t\t\t\t\tdata: value.get().data,\n\t\t\t\t\t\terror: value.get().error,\n\t\t\t\t\t\tisPending: value.get().isPending,\n\t\t\t\t\t})\n\t\t\t\t: options;\n\t\treturn $fetch<T>(path, {\n\t\t\t...opts,\n\t\t\tonSuccess: async (context) => {\n\t\t\t\tvalue.set({\n\t\t\t\t\tdata: context.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onSuccess?.(context);\n\t\t\t},\n\t\t\tasync onError(context) {\n\t\t\t\tvalue.set({\n\t\t\t\t\terror: context.error,\n\t\t\t\t\tdata: null,\n\t\t\t\t\tisPending: false,\n\t\t\t\t\tisRefetching: false,\n\t\t\t\t});\n\t\t\t\tawait opts?.onError?.(context);\n\t\t\t},\n\t\t\tasync onRequest(context) {\n\t\t\t\tconst currentValue = value.get();\n\t\t\t\tvalue.set({\n\t\t\t\t\tisPending: currentValue.data === null,\n\t\t\t\t\tdata: currentValue.data,\n\t\t\t\t\terror: null,\n\t\t\t\t\tisRefetching: true,\n\t\t\t\t});\n\t\t\t\tawait opts?.onRequest?.(context);\n\t\t\t},\n\t\t});\n\t};\n\n\tinitializedAtom = Array.isArray(initializedAtom)\n\t\t? initializedAtom\n\t\t: [initializedAtom];\n\tlet isMounted = false;\n\tfor (const initAtom of initializedAtom) {\n\t\tinitAtom.subscribe(() => {\n\t\t\tif (isMounted) {\n\t\t\t\tfn();\n\t\t\t} else {\n\t\t\t\tonMount(value, () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tisMounted = true;\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tvalue.off();\n\t\t\t\t\t\tinitAtom.off();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\treturn value;\n};\n","import type { BetterFetch } from \"@better-fetch/fetch\";\nimport { atom } from \"nanostores\";\nimport type { Prettify } from \"../types/helper\";\nimport type {\n\tClientOptions,\n\tInferSessionFromClient,\n\tInferUserFromClient,\n} from \"./types\";\nimport { useAuthQuery } from \"./query\";\n\nexport function getSessionAtom<Option extends ClientOptions>(\n\t$fetch: BetterFetch,\n) {\n\ttype UserWithAdditionalFields = InferUserFromClient<Option>;\n\ttype SessionWithAdditionalFields = InferSessionFromClient<Option>;\n\tconst $signal = atom<boolean>(false);\n\tconst session = useAuthQuery<{\n\t\tuser: Prettify<UserWithAdditionalFields>;\n\t\tsession: Prettify<SessionWithAdditionalFields>;\n\t}>($signal, \"/get-session\", $fetch, {\n\t\tmethod: \"GET\",\n\t});\n\treturn {\n\t\t$session: session,\n\t\t_sessionSignal: $signal,\n\t\t$Infer: {} as {\n\t\t\tSession: {\n\t\t\t\tsession: SessionWithAdditionalFields;\n\t\t\t\tuser: UserWithAdditionalFields;\n\t\t\t};\n\t\t},\n\t};\n}\n"],"mappings":"gFAAA,OAAS,eAAAA,MAAmB,sBAE5B,MAA0B,aCF1B,OAAiC,eAAAC,MAAmB,sBAG7C,IAAMC,EAAiB,CAC7B,GAAI,WACJ,KAA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,EAAS,IAAI,CACd,EACA,CAEH,CAAC,EAEF,OAAON,CACR,EC/FA,OAAS,QAAAO,MAAY,aASd,SAASC,EACfC,EACC,CAGD,IAAMC,EAAUC,EAAc,EAAK,EAOnC,MAAO,CACN,SAPeC,EAGbF,EAAS,eAAgBD,EAAQ,CACnC,OAAQ,KACT,CAAC,EAGA,eAAgBC,EAChB,OAAQ,CAAC,CAMV,CACD","names":["createFetch","betterFetch","redirectPlugin","context","addCurrentURL","url","csrfPlugin","options","data","error","betterFetch","BetterAuthError","csrfToken","getClientConfig","options","isCredentialsSupported","$fetch","createFetch","getBaseURL","csrfPlugin","redirectPlugin","addCurrentURL","pl","plugin","plugins","pluginsActions","pluginsAtoms","pluginPathMethods","atomListeners","path","getMethod","path","knownPathMethods","args","method","fetchOptions","query","body","createDynamicPathProxy","routes","client","atoms","atomListeners","createProxy","target","prop","fullPath","current","segment","_","__","routePath","letter","arg","argFetchOptions","options","context","matches","s","signal","val","atom","onMount","useAuthQuery","initializedAtom","path","$fetch","options","value","fn","opts","context","currentValue","isMounted","initAtom","atom","getSessionAtom","$fetch","$signal","atom","useAuthQuery"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkHO356XF6cjs = require('./chunk-HO356XF6.cjs');var _chunk6YSOZOBLcjs = require('./chunk-6YSOZOBL.cjs');function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=_chunkHO356XF6cjs.a.call(void 0, p),n={};for(let[a,g]of Object.entries(t))n[`use${_chunk6YSOZOBLcjs.a.call(void 0, a)}`]=g;let{$session:c,_sessionSignal:u}=_chunkHO356XF6cjs.d.call(void 0, e),y={...l,...n,$fetch:e,useSession:c};return _chunkHO356XF6cjs.b.call(void 0, y,e,f,{...t,_sessionSignal:u},m)}exports.a = O;
2
+ //# sourceMappingURL=chunk-F2I6F73J.cjs.map