better-auth 0.4.13 → 0.4.14-beta.1

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 (2) hide show
  1. package/dist/vue.js +1 -1
  2. package/package.json +1 -1
package/dist/vue.js CHANGED
@@ -1 +1 @@
1
- import{useStore as U}from"@nanostores/vue";import{createFetch as v}from"@better-fetch/fetch";var d=class extends Error{constructor(t,r){super(t),this.name="BetterAuthError",this.message=t,this.cause=r,this.stack=""}};function _(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function T(e,t="/api/auth"){return _(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function F(e,t){if(e)return T(e,t);let r=typeof process<"u"?process.env:{},i=r.BETTER_AUTH_URL||r.NEXT_PUBLIC_BETTER_AUTH_URL||r.PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_AUTH_URL||(r.BASE_URL!=="/"?r.BASE_URL:void 0);if(i)return T(i,t);if(typeof window<"u")return T(window.location.origin,t)}import"nanostores";import{betterFetch as $}from"@better-fetch/fetch";var S={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 t=new URL(e.url);t.searchParams.set("currentURL",window.location.href),e.url=t}return e}}},L={id:"csrf",name:"CSRF Check",async init(e,t){if(t?.method!=="GET"){t=t||{};let{data:r,error:i}=await $("/csrf",{body:void 0,baseURL:t.baseURL,plugins:[],method:"GET",credentials:"include",customFetchImpl:t.customFetchImpl});if(i){if(i.status===404)throw new d("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(i.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new d("Failed to fetch CSRF token: "+i.message)}let s=r?.csrfToken;t.body={...t?.body,csrfToken:s}}return t.credentials="include",{url:e,options:t}}};var B=e=>{let t=v({baseURL:F(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:[...e?.disableCSRFTokenCheck?[]:[L],S,b,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),r=e?.plugins||[],i={},s={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(n){return n==="/sign-out"||n==="/user/update"||n.startsWith("/sign-in")||n.startsWith("/sign-up")}}];for(let n of r)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(s,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:s,pluginPathMethods:u,atomListeners:o,$fetch:t}};function C(e){return e.charAt(0).toUpperCase()+e.slice(1)}function W(e,t,r){let i=t[e],{fetchOptions:s,query:u,...o}=r||{};return i||(s?.method?s.method:o&&Object.keys(o).length>0?"POST":"GET")}function x(e,t,r,i,s){function u(o=[]){return new Proxy(function(){},{get(n,c){let f=[...o,c],a=e;for(let l of f)if(a&&typeof a=="object"&&l in a)a=a[l];else{a=void 0;break}return typeof a=="function"?a:u(f)},apply:async(n,c,f)=>{let a="/"+o.map(R=>R.replace(/[A-Z]/g,y=>`-${y.toLowerCase()}`)).join("/"),l=f[0]||{},P=f[1]||{},{query:O,fetchOptions:p,...g}=l,h={...P,...p},m=W(a,r,l);return await t(a,{...h,body:m==="GET"?void 0:{...g,...h?.body||{}},query:O||h?.query,method:m,async onSuccess(R){await h?.onSuccess?.(R);let y=s?.find(I=>I.matcher(a));if(!y)return;let A=i[y.signal];if(!A)return;let k=A.get();setTimeout(()=>{A.set(!k)},10)}})}})}return u()}import{atom as G}from"nanostores";import"@better-fetch/fetch";import{atom as q,onMount as M}from"nanostores";var w=(e,t,r,i)=>{let s=q({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:s.get().data,error:s.get().error,isPending:s.get().isPending}):i;return r(t,{...n,onSuccess:async c=>{s.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){s.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let f=s.get();s.set({isPending:f.data===null,data:f.data,error:null,isRefetching:!0}),await n?.onRequest?.(c)}})};e=Array.isArray(e)?e:[e];let o=!1;for(let n of e)n.subscribe(()=>{o?u():M(s,()=>(u(),o=!0,()=>{s.off(),n.off()}))});return s};function E(e){let t=G(!1);return{$session:w(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function H(e){return`use${C(e)}`}function ge(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:i,$fetch:s,atomListeners:u}=B(e),o={};for(let[p,g]of Object.entries(i))o[H(p)]=()=>U(g);let{$session:n,_sessionSignal:c,$Infer:f}=E(s);function a(){return U(n)}function l(p){if(p){let g=U(c);return p("/api/auth/session",{ref:g}).then(m=>({data:m.data,isPending:!1,error:m.error}))}return a()}let P={...r,...o,useSession:l};return x(P,s,t,{...i,_sessionSignal:c},u)}export{ge as createAuthClient};
1
+ import{useStore as U}from"@nanostores/vue";import{createFetch as v}from"@better-fetch/fetch";var d=class extends Error{constructor(t,r){super(t),this.name="BetterAuthError",this.message=t,this.cause=r,this.stack=""}};function _(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function T(e,t="/api/auth"){return _(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function b(e,t){if(e)return T(e,t);let r=typeof process<"u"?process.env:{},i=r.BETTER_AUTH_URL||r.NEXT_PUBLIC_BETTER_AUTH_URL||r.PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_BETTER_AUTH_URL||r.NUXT_PUBLIC_AUTH_URL||(r.BASE_URL!=="/"?r.BASE_URL:void 0);if(i)return T(i,t);if(typeof window<"u")return T(window.location.origin,t)}import"nanostores";import{betterFetch as $}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)}}},S={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let t=new URL(e.url);t.searchParams.set("currentURL",window.location.href),e.url=t}return e}}},L={id:"csrf",name:"CSRF Check",async init(e,t){if(t?.method!=="GET"){t=t||{};let{data:r,error:i}=await $("/csrf",{body:void 0,baseURL:t.baseURL,plugins:[],method:"GET",credentials:"include",customFetchImpl:t.customFetchImpl});if(i){if(i.status===404)throw new d("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(i.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new d("Failed to fetch CSRF token: "+i.message)}let s=r?.csrfToken;t.body={...t?.body,csrfToken:s}}return t.credentials="include",{url:e,options:t}}};var B=e=>{let t=v({baseURL:b(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:[...e?.disableCSRFTokenCheck?[]:[L],F,S,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),r=e?.plugins||[],i={},s={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(n){return n==="/sign-out"||n==="/user/update"||n.startsWith("/sign-in")||n.startsWith("/sign-up")}}];for(let n of r)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(s,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:s,pluginPathMethods:u,atomListeners:o,$fetch:t}};function C(e){return e.charAt(0).toUpperCase()+e.slice(1)}function W(e,t,r){let i=t[e],{fetchOptions:s,query:u,...o}=r||{};return i||(s?.method?s.method:o&&Object.keys(o).length>0?"POST":"GET")}function x(e,t,r,i,s){function u(o=[]){return new Proxy(function(){},{get(n,c){let f=[...o,c],a=e;for(let l of f)if(a&&typeof a=="object"&&l in a)a=a[l];else{a=void 0;break}return typeof a=="function"?a:u(f)},apply:async(n,c,f)=>{let a="/"+o.map(h=>h.replace(/[A-Z]/g,y=>`-${y.toLowerCase()}`)).join("/"),l=f[0]||{},R=f[1]||{},{query:O,fetchOptions:p,...m}=l,g={...R,...p},P=W(a,r,l);return await t(a,{...g,body:P==="GET"?void 0:{...m,...g?.body||{}},query:O||g?.query,method:P,async onSuccess(h){await g?.onSuccess?.(h);let y=s?.find(I=>I.matcher(a));if(!y)return;let A=i[y.signal];if(!A)return;let k=A.get();setTimeout(()=>{A.set(!k)},10)}})}})}return u()}import{atom as G}from"nanostores";import"@better-fetch/fetch";import{atom as q,onMount as M}from"nanostores";var w=(e,t,r,i)=>{let s=q({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:s.get().data,error:s.get().error,isPending:s.get().isPending}):i;return r(t,{...n,onSuccess:async c=>{s.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){s.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let f=s.get();s.set({isPending:f.data===null,data:f.data,error:null,isRefetching:!0}),await n?.onRequest?.(c)}})};e=Array.isArray(e)?e:[e];let o=!1;for(let n of e)n.subscribe(()=>{o?u():M(s,()=>(u(),o=!0,()=>{s.off(),n.off()}))});return s};function E(e){let t=G(!1);return{$session:w(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function H(e){return`use${C(e)}`}function ge(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:i,$fetch:s,atomListeners:u}=B(e),o={};for(let[p,m]of Object.entries(i))o[H(p)]=()=>U(m);let{$session:n,_sessionSignal:c,$Infer:f}=E(s);function a(){return U(n)}function l(p){if(p){let m=U(c),g=e?.baseURL?new URL(e.baseURL).pathname:"/api/auth";return p(`${g}/session`,{ref:m}).then(h=>({data:h.data,isPending:!1,error:h.error}))}return a()}let R={...r,...o,useSession:l};return x(R,s,t,{...i,_sessionSignal:c},u)}export{ge as createAuthClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "0.4.13",
3
+ "version": "0.4.14-beta.1",
4
4
  "description": "The most comprehensive authentication library for TypeScript.",
5
5
  "type": "module",
6
6
  "repository": {