better-auth 0.5.2-beta.10 → 0.5.2-beta.11

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.
@@ -2,8 +2,8 @@ import * as nanostores from 'nanostores';
2
2
  import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-Da_cxgTI.cjs';
3
3
  import * as _better_fetch_fetch from '@better-fetch/fetch';
4
4
  import { BetterFetchOption } from '@better-fetch/fetch';
5
- import { o as organization, l as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth, k as multiSession } from '../index-BiscX-kB.cjs';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-BiscX-kB.cjs';
5
+ import { o as organization, l as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth, k as multiSession } from '../index-BFsm4pYA.cjs';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-BFsm4pYA.cjs';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.cjs';
8
8
  import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../auth-D7_h4yVD.cjs';
9
9
  import 'zod';
@@ -2,8 +2,8 @@ import * as nanostores from 'nanostores';
2
2
  import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CfnyN34h.js';
3
3
  import * as _better_fetch_fetch from '@better-fetch/fetch';
4
4
  import { BetterFetchOption } from '@better-fetch/fetch';
5
- import { o as organization, l as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth, k as multiSession } from '../index-C2LqoRnX.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-C2LqoRnX.js';
5
+ import { o as organization, l as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth, k as multiSession } from '../index-Ctg062Fg.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-Ctg062Fg.js';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.js';
8
8
  import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../auth-D1kVkHCi.js';
9
9
  import 'zod';
package/dist/client.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var R=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var s in t)R(e,s,{get:t[s],enumerable:!0})},j=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!G.call(e,r)&&r!==s&&R(e,r,{get:()=>t[r],enumerable:!(i=q(t,r))||i.enumerable});return e};var z=e=>j(R({},"__esModule",{value:!0}),e);var D={};H(D,{createAuthClient:()=>Q,useAuthQuery:()=>T});module.exports=z(D);var B=require("@better-fetch/fetch");var d=class extends Error{constructor(t,s){super(t),this.name="BetterAuthError",this.message=t,this.cause=s,this.stack=""}};function N(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function A(e,t="/api/auth"){return N(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function U(e,t){if(e)return A(e,t);let s=typeof process<"u"?process.env:{},i=s.BETTER_AUTH_URL||s.NEXT_PUBLIC_BETTER_AUTH_URL||s.PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_AUTH_URL||(s.BASE_URL!=="/"?s.BASE_URL:void 0);if(i)return A(i,t);if(typeof window<"u")return A(window.location.origin,t)}var ne=require("nanostores");var F=require("@better-fetch/fetch");var b={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},C={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:s,error:i}=await(0,F.betterFetch)("/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 r=s?.csrfToken;t.body={...t?.body,csrfToken:r}}return t.credentials="include",{url:e,options:t}}};var S=e=>{let t=(0,B.createFetch)({baseURL:U(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:[...e?.disableCSRFTokenCheck?[]:[L],b,C,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),s=e?.plugins||[],i={},r={},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 s)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(r,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:r,pluginPathMethods:u,atomListeners:o,$fetch:t}};function x(e){return e.charAt(0).toUpperCase()+e.slice(1)}function X(e,t,s){let i=t[e],{fetchOptions:r,query:u,...o}=s||{};return i||(r?.method?r.method:o&&Object.keys(o).length>0?"POST":"GET")}function w(e,t,s,i,r){function u(o=[]){return new Proxy(function(){},{get(n,c){let l=[...o,c],a=e;for(let f of l)if(a&&typeof a=="object"&&f in a)a=a[f];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(n,c,l)=>{let a="/"+o.map(y=>y.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),f=l[0]||{},m=l[1]||{},{query:k,fetchOptions:_,...$}=f,p={...m,..._},O=X(a,s,f);return await t(a,{...p,body:O==="GET"?void 0:{...$,...p?.body||{}},query:k||p?.query,method:O,async onSuccess(y){await p?.onSuccess?.(y);let h=r?.find(W=>W.matcher(a));if(!h)return;let P=i[h.signal];if(!P)return;let v=P.get();setTimeout(()=>{P.set(!v)},10)}})}})}return u()}var I=require("nanostores");var ae=require("@better-fetch/fetch"),g=require("nanostores"),T=(e,t,s,i)=>{let r=(0,g.atom)({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:r.get().data,error:r.get().error,isPending:r.get().isPending}):i;return s(t,{...n,onSuccess:async c=>{r.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){r.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let l=r.get();r.set({isPending:l.data===null,data:l.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():(0,g.onMount)(r,()=>(u(),o=!0,()=>{r.off(),n.off()}))});return r};function E(e){let t=(0,I.atom)(!1);return{$session:T(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function Q(e){let{pluginPathMethods:t,pluginsActions:s,pluginsAtoms:i,$fetch:r,atomListeners:u}=S(e),o={};for(let[f,m]of Object.entries(i))o[`use${x(f)}`]=m;let{$session:n,_sessionSignal:c}=E(r),l={...s,...o,$fetch:r,useSession:n};return w(l,r,t,{...i,_sessionSignal:c},u)}0&&(module.exports={createAuthClient,useAuthQuery});
1
+ "use strict";var R=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var s in t)R(e,s,{get:t[s],enumerable:!0})},j=(e,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!G.call(e,r)&&r!==s&&R(e,r,{get:()=>t[r],enumerable:!(i=q(t,r))||i.enumerable});return e};var z=e=>j(R({},"__esModule",{value:!0}),e);var Q={};H(Q,{createAuthClient:()=>D,useAuthQuery:()=>T});module.exports=z(Q);var B=require("@better-fetch/fetch");var d=class extends Error{constructor(t,s){super(t),this.name="BetterAuthError",this.message=t,this.cause=s,this.stack=""}};function N(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function A(e,t="/api/auth"){return N(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function U(e,t){if(e)return A(e,t);let s=typeof process<"u"?process.env:{},i=s.BETTER_AUTH_URL||s.NEXT_PUBLIC_BETTER_AUTH_URL||s.PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_AUTH_URL||(s.BASE_URL!=="/"?s.BASE_URL:void 0);if(i)return A(i,t);if(typeof window<"u")return A(window.location.origin,t)}var ne=require("nanostores");var F=require("@better-fetch/fetch");var b={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},C={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:s,error:i}=await(0,F.betterFetch)("/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 r=s?.csrfToken;t.body={...t?.body,csrfToken:r}}return t.credentials="include",{url:e,options:t}}};var S=e=>{let t=(0,B.createFetch)({baseURL:U(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:e?.disableDefaultFetchPlugins?e.fetchOptions?.plugins:[...e?.disableCSRFTokenCheck?[]:[L],b,C,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),s=e?.plugins||[],i={},r={},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 s)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(r,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:r,pluginPathMethods:u,atomListeners:o,$fetch:t}};function x(e){return e.charAt(0).toUpperCase()+e.slice(1)}function X(e,t,s){let i=t[e],{fetchOptions:r,query:u,...o}=s||{};return i||(r?.method?r.method:o&&Object.keys(o).length>0?"POST":"GET")}function w(e,t,s,i,r){function u(o=[]){return new Proxy(function(){},{get(n,c){let l=[...o,c],a=e;for(let f of l)if(a&&typeof a=="object"&&f in a)a=a[f];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(n,c,l)=>{let a="/"+o.map(y=>y.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),f=l[0]||{},m=l[1]||{},{query:k,fetchOptions:_,...$}=f,p={...m,..._},O=X(a,s,f);return await t(a,{...p,body:O==="GET"?void 0:{...$,...p?.body||{}},query:k||p?.query,method:O,async onSuccess(y){await p?.onSuccess?.(y);let h=r?.find(W=>W.matcher(a));if(!h)return;let P=i[h.signal];if(!P)return;let v=P.get();setTimeout(()=>{P.set(!v)},10)}})}})}return u()}var I=require("nanostores");var ae=require("@better-fetch/fetch"),g=require("nanostores"),T=(e,t,s,i)=>{let r=(0,g.atom)({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:r.get().data,error:r.get().error,isPending:r.get().isPending}):i;return s(t,{...n,onSuccess:async c=>{r.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){r.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let l=r.get();r.set({isPending:l.data===null,data:l.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():(0,g.onMount)(r,()=>(u(),o=!0,()=>{r.off(),n.off()}))});return r};function E(e){let t=(0,I.atom)(!1);return{$session:T(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function D(e){let{pluginPathMethods:t,pluginsActions:s,pluginsAtoms:i,$fetch:r,atomListeners:u}=S(e),o={};for(let[f,m]of Object.entries(i))o[`use${x(f)}`]=m;let{$session:n,_sessionSignal:c}=E(r),l={...s,...o,$fetch:r,useSession:n};return w(l,r,t,{...i,_sessionSignal:c},u)}0&&(module.exports={createAuthClient,useAuthQuery});
package/dist/client.d.cts CHANGED
@@ -190,7 +190,7 @@ declare function createAuthClient<Option extends ClientOptions>(options?: Option
190
190
  disableValidation?: boolean | undefined;
191
191
  };
192
192
  }>;
193
- })[];
193
+ })[] | undefined;
194
194
  headers?: (HeadersInit & (HeadersInit | {
195
195
  accept: "application/json" | "text/plain" | "application/octet-stream";
196
196
  "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
@@ -253,7 +253,7 @@ declare function createAuthClient<Option extends ClientOptions>(options?: Option
253
253
  output?: zod.ZodType | typeof Blob | typeof File;
254
254
  errorSchema?: zod.ZodType;
255
255
  disableValidation?: boolean;
256
- }, unknown, unknown, {}>;
256
+ }, unknown, unknown, unknown>;
257
257
  $Infer: {
258
258
  Session: {
259
259
  session: InferSessionFromClient<Option>;
package/dist/client.d.ts CHANGED
@@ -190,7 +190,7 @@ declare function createAuthClient<Option extends ClientOptions>(options?: Option
190
190
  disableValidation?: boolean | undefined;
191
191
  };
192
192
  }>;
193
- })[];
193
+ })[] | undefined;
194
194
  headers?: (HeadersInit & (HeadersInit | {
195
195
  accept: "application/json" | "text/plain" | "application/octet-stream";
196
196
  "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
@@ -253,7 +253,7 @@ declare function createAuthClient<Option extends ClientOptions>(options?: Option
253
253
  output?: zod.ZodType | typeof Blob | typeof File;
254
254
  errorSchema?: zod.ZodType;
255
255
  disableValidation?: boolean;
256
- }, unknown, unknown, {}>;
256
+ }, unknown, unknown, unknown>;
257
257
  $Infer: {
258
258
  Session: {
259
259
  session: InferSessionFromClient<Option>;
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import{createFetch as $}from"@better-fetch/fetch";var d=class extends Error{constructor(t,s){super(t),this.name="BetterAuthError",this.message=t,this.cause=s,this.stack=""}};function k(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function P(e,t="/api/auth"){return k(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function A(e,t){if(e)return P(e,t);let s=typeof process<"u"?process.env:{},i=s.BETTER_AUTH_URL||s.NEXT_PUBLIC_BETTER_AUTH_URL||s.PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_AUTH_URL||(s.BASE_URL!=="/"?s.BASE_URL:void 0);if(i)return P(i,t);if(typeof window<"u")return P(window.location.origin,t)}import"nanostores";import{betterFetch as _}from"@better-fetch/fetch";var T={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},O={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}}},U={id:"csrf",name:"CSRF Check",async init(e,t){if(t?.method!=="GET"){t=t||{};let{data:s,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 r=s?.csrfToken;t.body={...t?.body,csrfToken:r}}return t.credentials="include",{url:e,options:t}}};var F=e=>{let t=$({baseURL:A(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:[...e?.disableCSRFTokenCheck?[]:[U],T,O,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),s=e?.plugins||[],i={},r={},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 s)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(r,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:r,pluginPathMethods:u,atomListeners:o,$fetch:t}};function b(e){return e.charAt(0).toUpperCase()+e.slice(1)}function v(e,t,s){let i=t[e],{fetchOptions:r,query:u,...o}=s||{};return i||(r?.method?r.method:o&&Object.keys(o).length>0?"POST":"GET")}function C(e,t,s,i,r){function u(o=[]){return new Proxy(function(){},{get(n,c){let l=[...o,c],a=e;for(let f of l)if(a&&typeof a=="object"&&f in a)a=a[f];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(n,c,l)=>{let a="/"+o.map(m=>m.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),f=l[0]||{},g=l[1]||{},{query:S,fetchOptions:x,...w}=f,p={...g,...x},R=v(a,s,f);return await t(a,{...p,body:R==="GET"?void 0:{...w,...p?.body||{}},query:S||p?.query,method:R,async onSuccess(m){await p?.onSuccess?.(m);let h=r?.find(E=>E.matcher(a));if(!h)return;let y=i[h.signal];if(!y)return;let I=y.get();setTimeout(()=>{y.set(!I)},10)}})}})}return u()}import{atom as M}from"nanostores";import"@better-fetch/fetch";import{atom as W,onMount as q}from"nanostores";var L=(e,t,s,i)=>{let r=W({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:r.get().data,error:r.get().error,isPending:r.get().isPending}):i;return s(t,{...n,onSuccess:async c=>{r.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){r.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let l=r.get();r.set({isPending:l.data===null,data:l.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():q(r,()=>(u(),o=!0,()=>{r.off(),n.off()}))});return r};function B(e){let t=M(!1);return{$session:L(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function fe(e){let{pluginPathMethods:t,pluginsActions:s,pluginsAtoms:i,$fetch:r,atomListeners:u}=F(e),o={};for(let[f,g]of Object.entries(i))o[`use${b(f)}`]=g;let{$session:n,_sessionSignal:c}=B(r),l={...s,...o,$fetch:r,useSession:n};return C(l,r,t,{...i,_sessionSignal:c},u)}export{fe as createAuthClient,L as useAuthQuery};
1
+ import{createFetch as $}from"@better-fetch/fetch";var d=class extends Error{constructor(t,s){super(t),this.name="BetterAuthError",this.message=t,this.cause=s,this.stack=""}};function k(e){try{return new URL(e).pathname!=="/"}catch{throw new d(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function P(e,t="/api/auth"){return k(e)?e:(t=t.startsWith("/")?t:`/${t}`,`${e}${t}`)}function A(e,t){if(e)return P(e,t);let s=typeof process<"u"?process.env:{},i=s.BETTER_AUTH_URL||s.NEXT_PUBLIC_BETTER_AUTH_URL||s.PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_BETTER_AUTH_URL||s.NUXT_PUBLIC_AUTH_URL||(s.BASE_URL!=="/"?s.BASE_URL:void 0);if(i)return P(i,t);if(typeof window<"u")return P(window.location.origin,t)}import"nanostores";import{betterFetch as _}from"@better-fetch/fetch";var T={id:"redirect",name:"Redirect",hooks:{onSuccess(e){e.data?.url&&e.data?.redirect&&typeof window<"u"&&(window.location.href=e.data.url)}}},O={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}}},U={id:"csrf",name:"CSRF Check",async init(e,t){if(t?.method!=="GET"){t=t||{};let{data:s,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 r=s?.csrfToken;t.body={...t?.body,csrfToken:r}}return t.credentials="include",{url:e,options:t}}};var F=e=>{let t=$({baseURL:A(e?.fetchOptions?.baseURL||e?.baseURL),credentials:"include",method:"GET",...e?.fetchOptions,plugins:e?.disableDefaultFetchPlugins?e.fetchOptions?.plugins:[...e?.disableCSRFTokenCheck?[]:[U],T,O,...e?.fetchOptions?.plugins?.filter(n=>n!==void 0)||[],...e?.plugins?.flatMap(n=>n.fetchPlugins).filter(n=>n!==void 0)||[]]}),s=e?.plugins||[],i={},r={},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 s)n.getActions&&Object.assign(i,n.getActions?.(t)),n.getAtoms&&Object.assign(r,n.getAtoms?.(t)),n.pathMethods&&Object.assign(u,n.pathMethods),n.atomListeners&&o.push(...n.atomListeners);return{pluginsActions:i,pluginsAtoms:r,pluginPathMethods:u,atomListeners:o,$fetch:t}};function b(e){return e.charAt(0).toUpperCase()+e.slice(1)}function v(e,t,s){let i=t[e],{fetchOptions:r,query:u,...o}=s||{};return i||(r?.method?r.method:o&&Object.keys(o).length>0?"POST":"GET")}function C(e,t,s,i,r){function u(o=[]){return new Proxy(function(){},{get(n,c){let l=[...o,c],a=e;for(let f of l)if(a&&typeof a=="object"&&f in a)a=a[f];else{a=void 0;break}return typeof a=="function"?a:u(l)},apply:async(n,c,l)=>{let a="/"+o.map(m=>m.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),f=l[0]||{},g=l[1]||{},{query:S,fetchOptions:x,...w}=f,p={...g,...x},R=v(a,s,f);return await t(a,{...p,body:R==="GET"?void 0:{...w,...p?.body||{}},query:S||p?.query,method:R,async onSuccess(m){await p?.onSuccess?.(m);let h=r?.find(E=>E.matcher(a));if(!h)return;let y=i[h.signal];if(!y)return;let I=y.get();setTimeout(()=>{y.set(!I)},10)}})}})}return u()}import{atom as M}from"nanostores";import"@better-fetch/fetch";import{atom as W,onMount as q}from"nanostores";var L=(e,t,s,i)=>{let r=W({data:null,error:null,isPending:!1,isRefetching:!1}),u=()=>{let n=typeof i=="function"?i({data:r.get().data,error:r.get().error,isPending:r.get().isPending}):i;return s(t,{...n,onSuccess:async c=>{r.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await n?.onSuccess?.(c)},async onError(c){r.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await n?.onError?.(c)},async onRequest(c){let l=r.get();r.set({isPending:l.data===null,data:l.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():q(r,()=>(u(),o=!0,()=>{r.off(),n.off()}))});return r};function B(e){let t=M(!1);return{$session:L(t,"/session",e,{method:"GET"}),_sessionSignal:t,$Infer:{}}}function fe(e){let{pluginPathMethods:t,pluginsActions:s,pluginsAtoms:i,$fetch:r,atomListeners:u}=F(e),o={};for(let[f,g]of Object.entries(i))o[`use${b(f)}`]=g;let{$session:n,_sessionSignal:c}=B(r),l={...s,...o,$fetch:r,useSession:n};return C(l,r,t,{...i,_sessionSignal:c},u)}export{fe as createAuthClient,L as useAuthQuery};
@@ -4423,7 +4423,15 @@ declare const phoneNumber: (options?: {
4423
4423
  }>]>(...ctx: C): Promise<C extends [{
4424
4424
  asResponse: true;
4425
4425
  }] ? Response : {
4426
- user: UserWithPhoneNumber;
4426
+ user: {
4427
+ id: string;
4428
+ email: string;
4429
+ emailVerified: boolean;
4430
+ name: string;
4431
+ createdAt: Date;
4432
+ updatedAt: Date;
4433
+ image?: string | undefined;
4434
+ };
4427
4435
  session: any;
4428
4436
  }>;
4429
4437
  path: "/phone-number/verify";
@@ -4423,7 +4423,15 @@ declare const phoneNumber: (options?: {
4423
4423
  }>]>(...ctx: C): Promise<C extends [{
4424
4424
  asResponse: true;
4425
4425
  }] ? Response : {
4426
- user: UserWithPhoneNumber;
4426
+ user: {
4427
+ id: string;
4428
+ email: string;
4429
+ emailVerified: boolean;
4430
+ name: string;
4431
+ createdAt: Date;
4432
+ updatedAt: Date;
4433
+ image?: string | undefined;
4434
+ };
4427
4435
  session: any;
4428
4436
  }>;
4429
4437
  path: "/phone-number/verify";
package/dist/next-js.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var m=(e,s)=>{for(var r in s)o(e,r,{get:s[r],enumerable:!0})},R=(e,s,r,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of d(s))!l.call(e,t)&&t!==r&&o(e,t,{get:()=>s[t],enumerable:!(n=c(s,t))||n.enumerable});return e};var h=e=>R(o({},"__esModule",{value:!0}),e);var x={};m(x,{authMiddleware:()=>p,toNextJsHandler:()=>f});module.exports=h(x);var a=require("@better-fetch/fetch"),i=require("next/server");function f(e){let s=async r=>"handler"in e?e.handler(r):e(r);return{GET:s,POST:s}}function p(e){return async s=>{let r=new URL(s.url).origin,n=e?.basePath||"/api/auth",t=`${r}${n}/session`,u=(await(0,a.betterFetch)(t,{headers:{cookie:s.headers.get("cookie")||""}}).catch(q=>({data:null}))).data||null;return e.customRedirect?e.customRedirect(u,s):u?i.NextResponse.next():i.NextResponse.redirect(new URL(e.redirectTo||"/",r))}}0&&(module.exports={authMiddleware,toNextJsHandler});
1
+ "use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var l=(e,s)=>{for(var r in s)o(e,r,{get:s[r],enumerable:!0})},m=(e,s,r,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of d(s))!R.call(e,t)&&t!==r&&o(e,t,{get:()=>s[t],enumerable:!(n=c(s,t))||n.enumerable});return e};var h=e=>m(o({},"__esModule",{value:!0}),e);var U={};l(U,{authMiddleware:()=>f,toNextJsHandler:()=>p});module.exports=h(U);var u=require("@better-fetch/fetch"),i=require("next/server");function p(e){let s=async r=>"handler"in e?e.handler(r):e(r);return{GET:s,POST:s}}function f(e){return async s=>{let r=process.env.BETTER_AUTH_URL||new URL(s.url).origin,n=e?.basePath||"/api/auth",t=`${r}${n}/session`,a=(await(0,u.betterFetch)(t,{headers:{cookie:s.headers.get("cookie")||""}}).catch(P=>({data:null}))).data||null;return e.customRedirect?e.customRedirect(a,s):a?i.NextResponse.next():i.NextResponse.redirect(new URL(e.redirectTo||"/",r))}}0&&(module.exports={authMiddleware,toNextJsHandler});
package/dist/next-js.js CHANGED
@@ -1 +1 @@
1
- import{betterFetch as u}from"@better-fetch/fetch";import{NextResponse as n}from"next/server";function R(e){let s=async r=>"handler"in e?e.handler(r):e(r);return{GET:s,POST:s}}function h(e){return async s=>{let r=new URL(s.url).origin,o=e?.basePath||"/api/auth",i=`${r}${o}/session`,t=(await u(i,{headers:{cookie:s.headers.get("cookie")||""}}).catch(c=>({data:null}))).data||null;return e.customRedirect?e.customRedirect(t,s):t?n.next():n.redirect(new URL(e.redirectTo||"/",r))}}export{h as authMiddleware,R as toNextJsHandler};
1
+ import{betterFetch as a}from"@better-fetch/fetch";import{NextResponse as n}from"next/server";function m(e){let s=async r=>"handler"in e?e.handler(r):e(r);return{GET:s,POST:s}}function h(e){return async s=>{let r=process.env.BETTER_AUTH_URL||new URL(s.url).origin,o=e?.basePath||"/api/auth",i=`${r}${o}/session`,t=(await a(i,{headers:{cookie:s.headers.get("cookie")||""}}).catch(c=>({data:null}))).data||null;return e.customRedirect?e.customRedirect(t,s):t?n.next():n.redirect(new URL(e.redirectTo||"/",r))}}export{h as authMiddleware,m as toNextJsHandler};