better-auth 0.4.13 → 0.4.14-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.
@@ -2,10 +2,10 @@ 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, k 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 } from '../index-pILRgibH.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-pILRgibH.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-DhZ8Ofpl.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DhZ8Ofpl.js';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.js';
8
- import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../auth-C6fr77co.js';
8
+ import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../auth-BTj2ofMy.js';
9
9
  import 'zod';
10
10
  import '../schema-Dkt0LqYs.js';
11
11
  import 'better-call';
@@ -262,4 +262,16 @@ declare const genericOAuthClient: () => {
262
262
  $InferServerPlugin: ReturnType<typeof genericOAuth>;
263
263
  };
264
264
 
265
- export { adminClient, anonymousClient, genericOAuthClient, inferAdditionalFields, magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
265
+ declare const multiSessionClient: () => {
266
+ id: "multi-session";
267
+ $InferServerPlugin: ReturnType<typeof multiSession>;
268
+ pathMethods: {
269
+ "/multi-session/sign-out-device-sessions": "POST";
270
+ };
271
+ atomListeners: {
272
+ matcher(path: string): path is "/multi-session/set-active";
273
+ signal: "_sessionSignal";
274
+ }[];
275
+ };
276
+
277
+ export { adminClient, anonymousClient, genericOAuthClient, inferAdditionalFields, magicLinkClient, multiSessionClient, organizationClient, phoneNumberClient, usernameClient };
@@ -1 +1 @@
1
- import{atom as d}from"nanostores";var u=class extends Error{path;constructor(t,a){super(t),this.path=a}},p=class{constructor(t){this.s=t;this.statements=t}statements;newRole(t){return new m(t)}},m=class n{statements;constructor(t){this.statements=t}authorize(t,a){for(let[i,e]of Object.entries(t)){let s=this.statements[i];if(!s)return{success:!1,error:`You are not allowed to access resource: ${i}`};let o=a==="OR"?e.some(r=>s.includes(r)):e.every(r=>s.includes(r));return o?{success:o}:{success:!1,error:`unauthorized to access resource "${i}"`}}return{success:!1,error:"Not authorized"}}static fromString(t){let a=JSON.parse(t);if(typeof a!="object")throw new u("statements is not an object",".");for(let[i,e]of Object.entries(a)){if(typeof i!="string")throw new u("invalid resource identifier",i);if(!Array.isArray(e))throw new u("actions is not an array",i);for(let s=0;s<e.length;s++)if(typeof e[s]!="string")throw new u("action is not a string",`${i}[${s}]`)}return new n(a)}toString(){return JSON.stringify(this.statements)}};var y=n=>new p(n),h={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"]},f=y(h),k=f.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"]}),B=f.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"]}),F=f.newRole({organization:[],member:[],invitation:[]});import{createFetch as X}from"@better-fetch/fetch";import"nanostores";import{betterFetch as j}from"@better-fetch/fetch";import{atom as ue}from"nanostores";import"@better-fetch/fetch";import{atom as S,onMount as O}from"nanostores";var l=(n,t,a,i)=>{let e=S({data:null,error:null,isPending:!1,isRefetching:!1}),s=()=>{let r=typeof i=="function"?i({data:e.get().data,error:e.get().error,isPending:e.get().isPending}):i;return a(t,{...r,onSuccess:async c=>{e.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await r?.onSuccess?.(c)},async onError(c){e.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await r?.onError?.(c)},async onRequest(c){let g=e.get();e.set({isPending:g.data===null,data:g.data,error:null,isRefetching:!0}),await r?.onRequest?.(c)}})};n=Array.isArray(n)?n:[n];let o=!1;for(let r of n)r.subscribe(()=>{o?s():O(e,()=>(s(),o=!0,()=>{e.off(),r.off()}))});return e};var Be=n=>{let t=d(void 0),a=d(!1),i=d(!1);return{id:"organization",$InferServerPlugin:{},getActions:e=>({$Infer:{ActiveOrganization:{},Organization:{},Invitation:{},Member:{}},organization:{setActive(s){t.set(s)},hasPermission:async s=>await e("/organization/has-permission",{method:"POST",body:{permission:s.permission},...s.fetchOptions})}}),getAtoms:e=>{let s=l(a,"/organization/list",e,{method:"GET"}),o=l([t,i],"/organization/activate",e,()=>({method:"POST",credentials:"include",body:{orgId:t.get()}}));return{_listOrg:a,_activeOrgSignal:i,activeOrganization:o,listOrganizations:s}},atomListeners:[{matcher(e){return e==="/organization/create"||e==="/organization/delete"},signal:"_listOrg"},{matcher(e){return e.startsWith("/organization")},signal:"_activeOrgSignal"}]}};var ve=()=>({id:"username",$InferServerPlugin:{}});import{WebAuthnError as A,startAuthentication as b,startRegistration as T}from"@simplewebauthn/browser";import{atom as R}from"nanostores";var x=(n,{_listPasskeys:t})=>({signIn:{passkey:async(e,s)=>{let o=await n("/passkey/generate-authenticate-options",{method:"POST",body:{email:e?.email}});if(!o.data)return o;try{let r=await b(o.data,e?.autoFill||!1),c=await n("/passkey/verify-authentication",{body:{response:r},...e?.fetchOptions,...s,method:"POST"});if(!c.data)return c}catch(r){console.log(r)}}},passkey:{addPasskey:async(e,s)=>{let o=await n("/passkey/generate-register-options",{method:"GET"});if(!o.data)return o;try{let r=await T(o.data),c=await n("/passkey/verify-registration",{...e?.fetchOptions,...s,body:{response:r,name:e?.name},method:"POST"});if(!c.data)return c;t.set(Math.random())}catch(r){return r instanceof A?r.code==="ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED"?{data:null,error:{message:"previously registered",status:400,statusText:"BAD_REQUEST"}}:r.code==="ERROR_CEREMONY_ABORTED"?{data:null,error:{message:"registration cancelled",status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:r.message,status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:r instanceof Error?r.message:"unknown error",status:500,statusText:"INTERNAL_SERVER_ERROR"}}}}},$Infer:{}}),_e=()=>{let n=R();return{id:"passkey",$InferServerPlugin:{},getActions:t=>x(t,{_listPasskeys:n}),getAtoms(t){return{listPasskeys:l(n,"/passkey/list-user-passkeys",t,{method:"GET",credentials:"include"}),_listPasskeys:n}},pathMethods:{"/passkey/register":"POST","/passkey/authenticate":"POST"},atomListeners:[{matcher(t){return t==="/passkey/verify-registration"||t==="/passkey/delete-passkey"},signal:"_listPasskeys"}]}};var $e=(n={redirect:!0,twoFactorPage:"/"})=>({id:"two-factor",$InferServerPlugin:{},atomListeners:[{matcher:t=>t==="/two-factor/enable"||t==="/two-factor/send-otp"||t==="/two-factor/disable",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){t.data?.twoFactorRedirect&&(n.redirect||n.twoFactorPage)&&typeof window<"u"&&(window.location.href=n.twoFactorPage)}}}]});var Ne=()=>({id:"magic-link",$InferServerPlugin:{}});var We=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(n){return n==="/phone-number/update"||n==="/phone-number/verify"},signal:"_sessionSignal"}]});var Ge=()=>({id:"anonymous",$InferServerPlugin:{},pathMethods:{"/sign-in/anonymous":"POST"}});var He=n=>({id:"additional-fields-client",$InferServerPlugin:{}});var Je=()=>({id:"better-auth-client",$InferServerPlugin:{}});var Ve=()=>({id:"generic-oauth-client",$InferServerPlugin:{}});export{Je as adminClient,Ge as anonymousClient,Ve as genericOAuthClient,x as getPasskeyActions,He as inferAdditionalFields,Ne as magicLinkClient,Be as organizationClient,_e as passkeyClient,We as phoneNumberClient,$e as twoFactorClient,ve as usernameClient};
1
+ import{atom as d}from"nanostores";var c=class extends Error{path;constructor(t,a){super(t),this.path=a}},p=class{constructor(t){this.s=t;this.statements=t}statements;newRole(t){return new m(t)}},m=class n{statements;constructor(t){this.statements=t}authorize(t,a){for(let[i,e]of Object.entries(t)){let s=this.statements[i];if(!s)return{success:!1,error:`You are not allowed to access resource: ${i}`};let o=a==="OR"?e.some(r=>s.includes(r)):e.every(r=>s.includes(r));return o?{success:o}:{success:!1,error:`unauthorized to access resource "${i}"`}}return{success:!1,error:"Not authorized"}}static fromString(t){let a=JSON.parse(t);if(typeof a!="object")throw new c("statements is not an object",".");for(let[i,e]of Object.entries(a)){if(typeof i!="string")throw new c("invalid resource identifier",i);if(!Array.isArray(e))throw new c("actions is not an array",i);for(let s=0;s<e.length;s++)if(typeof e[s]!="string")throw new c("action is not a string",`${i}[${s}]`)}return new n(a)}toString(){return JSON.stringify(this.statements)}};var y=n=>new p(n),h={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"]},f=y(h),k=f.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"]}),B=f.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"]}),F=f.newRole({organization:[],member:[],invitation:[]});import{createFetch as X}from"@better-fetch/fetch";import"nanostores";import{betterFetch as j}from"@better-fetch/fetch";import{atom as ce}from"nanostores";import"@better-fetch/fetch";import{atom as S,onMount as O}from"nanostores";var l=(n,t,a,i)=>{let e=S({data:null,error:null,isPending:!1,isRefetching:!1}),s=()=>{let r=typeof i=="function"?i({data:e.get().data,error:e.get().error,isPending:e.get().isPending}):i;return a(t,{...r,onSuccess:async u=>{e.set({data:u.data,error:null,isPending:!1,isRefetching:!1}),await r?.onSuccess?.(u)},async onError(u){e.set({error:u.error,data:null,isPending:!1,isRefetching:!1}),await r?.onError?.(u)},async onRequest(u){let g=e.get();e.set({isPending:g.data===null,data:g.data,error:null,isRefetching:!0}),await r?.onRequest?.(u)}})};n=Array.isArray(n)?n:[n];let o=!1;for(let r of n)r.subscribe(()=>{o?s():O(e,()=>(s(),o=!0,()=>{e.off(),r.off()}))});return e};var Be=n=>{let t=d(void 0),a=d(!1),i=d(!1);return{id:"organization",$InferServerPlugin:{},getActions:e=>({$Infer:{ActiveOrganization:{},Organization:{},Invitation:{},Member:{}},organization:{setActive(s){t.set(s)},hasPermission:async s=>await e("/organization/has-permission",{method:"POST",body:{permission:s.permission},...s.fetchOptions})}}),getAtoms:e=>{let s=l(a,"/organization/list",e,{method:"GET"}),o=l([t,i],"/organization/activate",e,()=>({method:"POST",credentials:"include",body:{orgId:t.get()}}));return{_listOrg:a,_activeOrgSignal:i,activeOrganization:o,listOrganizations:s}},atomListeners:[{matcher(e){return e==="/organization/create"||e==="/organization/delete"},signal:"_listOrg"},{matcher(e){return e.startsWith("/organization")},signal:"_activeOrgSignal"}]}};var ve=()=>({id:"username",$InferServerPlugin:{}});import{WebAuthnError as A,startAuthentication as T,startRegistration as b}from"@simplewebauthn/browser";import{atom as R}from"nanostores";var x=(n,{_listPasskeys:t})=>({signIn:{passkey:async(e,s)=>{let o=await n("/passkey/generate-authenticate-options",{method:"POST",body:{email:e?.email}});if(!o.data)return o;try{let r=await T(o.data,e?.autoFill||!1),u=await n("/passkey/verify-authentication",{body:{response:r},...e?.fetchOptions,...s,method:"POST"});if(!u.data)return u}catch(r){console.log(r)}}},passkey:{addPasskey:async(e,s)=>{let o=await n("/passkey/generate-register-options",{method:"GET"});if(!o.data)return o;try{let r=await b(o.data),u=await n("/passkey/verify-registration",{...e?.fetchOptions,...s,body:{response:r,name:e?.name},method:"POST"});if(!u.data)return u;t.set(Math.random())}catch(r){return r instanceof A?r.code==="ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED"?{data:null,error:{message:"previously registered",status:400,statusText:"BAD_REQUEST"}}:r.code==="ERROR_CEREMONY_ABORTED"?{data:null,error:{message:"registration cancelled",status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:r.message,status:400,statusText:"BAD_REQUEST"}}:{data:null,error:{message:r instanceof Error?r.message:"unknown error",status:500,statusText:"INTERNAL_SERVER_ERROR"}}}}},$Infer:{}}),_e=()=>{let n=R();return{id:"passkey",$InferServerPlugin:{},getActions:t=>x(t,{_listPasskeys:n}),getAtoms(t){return{listPasskeys:l(n,"/passkey/list-user-passkeys",t,{method:"GET",credentials:"include"}),_listPasskeys:n}},pathMethods:{"/passkey/register":"POST","/passkey/authenticate":"POST"},atomListeners:[{matcher(t){return t==="/passkey/verify-registration"||t==="/passkey/delete-passkey"},signal:"_listPasskeys"}]}};var $e=(n={redirect:!0,twoFactorPage:"/"})=>({id:"two-factor",$InferServerPlugin:{},atomListeners:[{matcher:t=>t==="/two-factor/enable"||t==="/two-factor/send-otp"||t==="/two-factor/disable",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){t.data?.twoFactorRedirect&&(n.redirect||n.twoFactorPage)&&typeof window<"u"&&(window.location.href=n.twoFactorPage)}}}]});var Ne=()=>({id:"magic-link",$InferServerPlugin:{}});var We=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(n){return n==="/phone-number/update"||n==="/phone-number/verify"},signal:"_sessionSignal"}]});var Ge=()=>({id:"anonymous",$InferServerPlugin:{},pathMethods:{"/sign-in/anonymous":"POST"}});var He=n=>({id:"additional-fields-client",$InferServerPlugin:{}});var Je=()=>({id:"better-auth-client",$InferServerPlugin:{}});var Ve=()=>({id:"generic-oauth-client",$InferServerPlugin:{}});var Ye=()=>({id:"multi-session",$InferServerPlugin:{},pathMethods:{"/multi-session/sign-out-device-sessions":"POST"},atomListeners:[{matcher(n){return n==="/multi-session/set-active"},signal:"_sessionSignal"}]});export{Je as adminClient,Ge as anonymousClient,Ve as genericOAuthClient,x as getPasskeyActions,He as inferAdditionalFields,Ne as magicLinkClient,Ye as multiSessionClient,Be as organizationClient,_e as passkeyClient,We as phoneNumberClient,$e as twoFactorClient,ve as usernameClient};
package/dist/client.d.ts CHANGED
@@ -6,7 +6,7 @@ import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/
6
6
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
7
7
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
8
8
  export { AtomListener, InferPluginsFromClient } from './types.js';
9
- import './auth-C6fr77co.js';
9
+ import './auth-BTj2ofMy.js';
10
10
  import 'kysely';
11
11
  import './schema-Dkt0LqYs.js';
12
12
  import 'better-call';
package/dist/cookies.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'better-call';
2
- export { s as BetterAuthCookies, E as EligibleCookies, r as createCookieGetter, u as deleteSessionCookie, q as getCookies, v as parseSetCookieHeader, t as setSessionCookie } from './auth-C6fr77co.js';
2
+ export { s as BetterAuthCookies, E as EligibleCookies, r as createCookieGetter, u as deleteSessionCookie, q as getCookies, w as parseCookies, v as parseSetCookieHeader, t as setSessionCookie } from './auth-BTj2ofMy.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import './schema-Dkt0LqYs.js';
package/dist/cookies.js CHANGED
@@ -1 +1 @@
1
- import{TimeSpan as m}from"oslo";var u=class extends Error{constructor(r,o){super(r),this.name="BetterAuthError",this.message=r,this.cause=o,this.stack=""}};function f(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:(e.baseURL?e.baseURL.startsWith("https://"):!1)||process.env.NODE_ENV==="production")?"__Secure-":"",t="better-auth",a=e.session?.expiresIn||new m(7,"d").seconds(),s=!!e.advanced?.crossSubDomainCookies?.enabled,n=s?e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0):void 0;if(s&&!n)throw new u("baseURL is required when crossSubdomainCookies are enabled");let i=s?"none":"lax";return{sessionToken:{name:`${o}${t}.session_token`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:a,...s?{domain:n}:{}}},csrfToken:{name:`${o}${t}.csrf_token`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*60*24*7,...s?{domain:n}:{}}},state:{name:`${o}${t}.state`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}},pkCodeVerifier:{name:`${o}${t}.pk_code_verifier`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}},dontRememberToken:{name:`${o}${t}.dont_remember`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,...s?{domain:n}:{}}},nonce:{name:`${o}${t}.nonce`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}}}}function l(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:e.baseURL?.startsWith("https://")||process.env.NODE_ENV==="production")?"__Secure-":"",t="better-auth",a=e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0);function s(n,i){let c=e.advanced?.crossSubDomainCookies?.enabled?e.advanced.crossSubDomainCookies.additionalCookies?.includes(n):void 0;return{name:process.env.NODE_ENV==="production"?`${o}${t}.${n}`:`${t}.${n}`,options:{secure:!!o,sameSite:"lax",path:"/",maxAge:60*15,...i,...c?{domain:a}:{}}}}return s}async function x(e,r,o,t){let a=e.context.authCookies.sessionToken.options;a.maxAge=o?void 0:e.context.sessionConfig.expiresIn,await e.setSignedCookie(e.context.authCookies.sessionToken.name,r,e.context.secret,{...a,...t}),o&&await e.setSignedCookie(e.context.authCookies.dontRememberToken.name,"true",e.context.secret,e.context.authCookies.dontRememberToken.options)}function g(e){e.setCookie(e.context.authCookies.sessionToken.name,"",{maxAge:0}),e.setCookie(e.context.authCookies.dontRememberToken.name,"",{maxAge:0})}function O(e){let r=new Map;return e.split(", ").forEach(t=>{let[a,...s]=t.split("; "),[n,i]=a.split("="),c={value:i};s.forEach(p=>{let[d,k]=p.split("=");c[d.toLowerCase()]=k||!0}),r.set(n,c)}),r}export{l as createCookieGetter,g as deleteSessionCookie,f as getCookies,O as parseSetCookieHeader,x as setSessionCookie};
1
+ import{TimeSpan as m}from"oslo";var u=class extends Error{constructor(i,o){super(i),this.name="BetterAuthError",this.message=i,this.cause=o,this.stack=""}};function l(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:(e.baseURL?e.baseURL.startsWith("https://"):!1)||process.env.NODE_ENV==="production")?"__Secure-":"",t="better-auth",r=e.session?.expiresIn||new m(7,"d").seconds(),s=!!e.advanced?.crossSubDomainCookies?.enabled,n=s?e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0):void 0;if(s&&!n)throw new u("baseURL is required when crossSubdomainCookies are enabled");let a=s?"none":"lax";return{sessionToken:{name:`${o}${t}.session_token`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,maxAge:r,...s?{domain:n}:{}}},csrfToken:{name:`${o}${t}.csrf_token`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,maxAge:60*60*24*7,...s?{domain:n}:{}}},state:{name:`${o}${t}.state`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}},pkCodeVerifier:{name:`${o}${t}.pk_code_verifier`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}},dontRememberToken:{name:`${o}${t}.dont_remember`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,...s?{domain:n}:{}}},nonce:{name:`${o}${t}.nonce`,options:{httpOnly:!0,sameSite:a,path:"/",secure:!!o,maxAge:60*15,...s?{domain:n}:{}}}}}function b(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:e.baseURL?.startsWith("https://")||process.env.NODE_ENV==="production")?"__Secure-":"",t="better-auth",r=e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0);function s(n,a){let c=e.advanced?.crossSubDomainCookies?.enabled?e.advanced.crossSubDomainCookies.additionalCookies?.includes(n):void 0;return{name:process.env.NODE_ENV==="production"?`${o}${t}.${n}`:`${t}.${n}`,options:{secure:!!o,sameSite:"lax",path:"/",maxAge:60*15,...a,...c?{domain:r}:{}}}}return s}async function x(e,i,o,t){let r=e.context.authCookies.sessionToken.options;r.maxAge=o?void 0:e.context.sessionConfig.expiresIn,await e.setSignedCookie(e.context.authCookies.sessionToken.name,i,e.context.secret,{...r,...t}),o&&await e.setSignedCookie(e.context.authCookies.dontRememberToken.name,"true",e.context.secret,e.context.authCookies.dontRememberToken.options)}function g(e){e.setCookie(e.context.authCookies.sessionToken.name,"",{maxAge:0}),e.setCookie(e.context.authCookies.dontRememberToken.name,"",{maxAge:0})}function O(e){let i=new Map;return e.split(", ").forEach(t=>{let[r,...s]=t.split("; "),[n,a]=r.split("="),c={value:a};s.forEach(p=>{let[k,d]=p.split("=");c[k.toLowerCase()]=d||!0}),i.set(n,c)}),i}function S(e){let i=e.split("; "),o=new Map;return i.forEach(t=>{let[r,s]=t.split("=");o.set(r,s)}),o}export{b as createCookieGetter,g as deleteSessionCookie,l as getCookies,S as parseCookies,O as parseSetCookieHeader,x as setSessionCookie};
package/dist/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as Adapter, B as BetterAuthOptions, W as Where, F as FieldAttribute, y as FieldType, K as KyselyDatabaseType } from './auth-C6fr77co.js';
2
- export { V as BetterAuthDbSchema, D as FieldAttributeConfig, U as InferFieldsFromOptions, T as InferFieldsFromPlugins, N as InferFieldsInput, O as InferFieldsInputClient, M as InferFieldsOutput, L as InferValueType, C as InternalAdapter, Q as PluginFieldAttribute, J as createFieldAttribute, z as createInternalAdapter, X as getAuthTables } from './auth-C6fr77co.js';
1
+ import { A as Adapter, B as BetterAuthOptions, W as Where, F as FieldAttribute, z as FieldType, K as KyselyDatabaseType } from './auth-BTj2ofMy.js';
2
+ export { X as BetterAuthDbSchema, J as FieldAttributeConfig, V as InferFieldsFromOptions, U as InferFieldsFromPlugins, O as InferFieldsInput, Q as InferFieldsInputClient, N as InferFieldsOutput, M as InferValueType, D as InternalAdapter, T as PluginFieldAttribute, L as createFieldAttribute, C as createInternalAdapter, Y as getAuthTables } from './auth-BTj2ofMy.js';
3
3
  import { z } from 'zod';
4
4
  import 'kysely';
5
5
  import './schema-Dkt0LqYs.js';
@@ -5,7 +5,7 @@ import { P as Prettify } from './helper-DPDj8Nix.js';
5
5
  import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CfnyN34h.js';
6
6
  import * as _better_fetch_fetch from '@better-fetch/fetch';
7
7
  import { BetterFetch, BetterFetchOption } from '@better-fetch/fetch';
8
- import { H as HookEndpointContext, p as AuthContext } from './auth-C6fr77co.js';
8
+ import { H as HookEndpointContext, p as AuthContext } from './auth-BTj2ofMy.js';
9
9
  import * as nanostores from 'nanostores';
10
10
  import { atom } from 'nanostores';
11
11
  import * as _simplewebauthn_types from '@simplewebauthn/types';
@@ -5568,4 +5568,187 @@ declare const genericOAuth: (options: GenericOAuthOptions) => {
5568
5568
  };
5569
5569
  };
5570
5570
 
5571
- export { type AnonymousOptions as A, type Invitation as I, type Member as M, type OrganizationOptions as O, type PasskeyOptions as P, type UserWithPhoneNumber as U, twoFactorClient as a, type Passkey as b, passkeyClient as c, phoneNumber as d, anonymous as e, type UserWithRole as f, getPasskeyActions as g, adminMiddleware as h, admin as i, genericOAuth as j, type Organization as k, magicLink as m, organization as o, passkey as p, twoFactor as t, username as u };
5571
+ interface MultiSessionConfig {
5572
+ /**
5573
+ * The maximum number of sessions a user can have
5574
+ * at a time
5575
+ * @default 5
5576
+ */
5577
+ maximumSessions?: number;
5578
+ }
5579
+ declare const multiSession: (options?: MultiSessionConfig) => {
5580
+ id: "multi-session";
5581
+ endpoints: {
5582
+ listDeviceSessions: {
5583
+ <C extends [better_call.Context<"/multi-session/list-device-sessions", {
5584
+ method: "GET";
5585
+ requireHeaders: true;
5586
+ }>]>(...ctx: C): Promise<C extends [{
5587
+ asResponse: true;
5588
+ }] ? Response : {
5589
+ session: Session;
5590
+ user: User;
5591
+ }[]>;
5592
+ path: "/multi-session/list-device-sessions";
5593
+ options: {
5594
+ method: "GET";
5595
+ requireHeaders: true;
5596
+ };
5597
+ method: better_call.Method | better_call.Method[];
5598
+ headers: Headers;
5599
+ };
5600
+ setActiveSession: {
5601
+ <C extends [better_call.Context<"/multi-session/set-active", {
5602
+ method: "POST";
5603
+ body: z.ZodObject<{
5604
+ sessionId: z.ZodString;
5605
+ }, "strip", z.ZodTypeAny, {
5606
+ sessionId: string;
5607
+ }, {
5608
+ sessionId: string;
5609
+ }>;
5610
+ requireHeaders: true;
5611
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
5612
+ session: {
5613
+ session: {
5614
+ id: string;
5615
+ userId: string;
5616
+ expiresAt: Date;
5617
+ ipAddress?: string | undefined;
5618
+ userAgent?: string | undefined;
5619
+ };
5620
+ user: {
5621
+ id: string;
5622
+ email: string;
5623
+ emailVerified: boolean;
5624
+ name: string;
5625
+ createdAt: Date;
5626
+ updatedAt: Date;
5627
+ image?: string | undefined;
5628
+ };
5629
+ };
5630
+ }>, better_call.EndpointOptions>[];
5631
+ }>]>(...ctx: C): Promise<C extends [{
5632
+ asResponse: true;
5633
+ }] ? Response : {
5634
+ session: Session;
5635
+ user: User;
5636
+ }>;
5637
+ path: "/multi-session/set-active";
5638
+ options: {
5639
+ method: "POST";
5640
+ body: z.ZodObject<{
5641
+ sessionId: z.ZodString;
5642
+ }, "strip", z.ZodTypeAny, {
5643
+ sessionId: string;
5644
+ }, {
5645
+ sessionId: string;
5646
+ }>;
5647
+ requireHeaders: true;
5648
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
5649
+ session: {
5650
+ session: {
5651
+ id: string;
5652
+ userId: string;
5653
+ expiresAt: Date;
5654
+ ipAddress?: string | undefined;
5655
+ userAgent?: string | undefined;
5656
+ };
5657
+ user: {
5658
+ id: string;
5659
+ email: string;
5660
+ emailVerified: boolean;
5661
+ name: string;
5662
+ createdAt: Date;
5663
+ updatedAt: Date;
5664
+ image?: string | undefined;
5665
+ };
5666
+ };
5667
+ }>, better_call.EndpointOptions>[];
5668
+ };
5669
+ method: better_call.Method | better_call.Method[];
5670
+ headers: Headers;
5671
+ };
5672
+ DeviceSession: {
5673
+ <C extends [better_call.Context<"/multi-session/revoke", {
5674
+ method: "POST";
5675
+ body: z.ZodObject<{
5676
+ sessionId: z.ZodString;
5677
+ }, "strip", z.ZodTypeAny, {
5678
+ sessionId: string;
5679
+ }, {
5680
+ sessionId: string;
5681
+ }>;
5682
+ requireHeaders: true;
5683
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
5684
+ session: {
5685
+ session: {
5686
+ id: string;
5687
+ userId: string;
5688
+ expiresAt: Date;
5689
+ ipAddress?: string | undefined;
5690
+ userAgent?: string | undefined;
5691
+ };
5692
+ user: {
5693
+ id: string;
5694
+ email: string;
5695
+ emailVerified: boolean;
5696
+ name: string;
5697
+ createdAt: Date;
5698
+ updatedAt: Date;
5699
+ image?: string | undefined;
5700
+ };
5701
+ };
5702
+ }>, better_call.EndpointOptions>[];
5703
+ }>]>(...ctx: C): Promise<C extends [{
5704
+ asResponse: true;
5705
+ }] ? Response : {
5706
+ success: boolean;
5707
+ }>;
5708
+ path: "/multi-session/revoke";
5709
+ options: {
5710
+ method: "POST";
5711
+ body: z.ZodObject<{
5712
+ sessionId: z.ZodString;
5713
+ }, "strip", z.ZodTypeAny, {
5714
+ sessionId: string;
5715
+ }, {
5716
+ sessionId: string;
5717
+ }>;
5718
+ requireHeaders: true;
5719
+ use: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
5720
+ session: {
5721
+ session: {
5722
+ id: string;
5723
+ userId: string;
5724
+ expiresAt: Date;
5725
+ ipAddress?: string | undefined;
5726
+ userAgent?: string | undefined;
5727
+ };
5728
+ user: {
5729
+ id: string;
5730
+ email: string;
5731
+ emailVerified: boolean;
5732
+ name: string;
5733
+ createdAt: Date;
5734
+ updatedAt: Date;
5735
+ image?: string | undefined;
5736
+ };
5737
+ };
5738
+ }>, better_call.EndpointOptions>[];
5739
+ };
5740
+ method: better_call.Method | better_call.Method[];
5741
+ headers: Headers;
5742
+ };
5743
+ };
5744
+ hooks: {
5745
+ after: {
5746
+ matcher: (context: HookEndpointContext) => boolean;
5747
+ handler: better_call.Endpoint<better_call.Handler<string, better_call.EndpointOptions, {
5748
+ response: Response | undefined;
5749
+ } | undefined>, better_call.EndpointOptions>;
5750
+ }[];
5751
+ };
5752
+ };
5753
+
5754
+ export { type AnonymousOptions as A, type Invitation as I, type Member as M, type OrganizationOptions as O, type PasskeyOptions as P, type UserWithPhoneNumber as U, twoFactorClient as a, type Passkey as b, passkeyClient as c, phoneNumber as d, anonymous as e, type UserWithRole as f, getPasskeyActions as g, adminMiddleware as h, admin as i, genericOAuth as j, multiSession as k, type Organization as l, magicLink as m, organization as o, passkey as p, twoFactor as t, username as u };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Adapter, j as AdditionalSessionFieldsInput, k as AdditionalSessionFieldsOutput, h as AdditionalUserFieldsInput, i as AdditionalUserFieldsOutput, a as Auth, p as AuthContext, s as BetterAuthCookies, B as BetterAuthOptions, b as BetterAuthPlugin, E as EligibleCookies, G as GenericEndpointContext, H as HookEndpointContext, m as InferPluginTypes, l as InferSession, I as InferUser, P as PluginSchema, R as RateLimit, S as SecondaryStorage, W as Where, g as betterAuth, r as createCookieGetter, w as createLogger, u as deleteSessionCookie, q as getCookies, n as init, x as logger, v as parseSetCookieHeader, t as setSessionCookie } from './auth-C6fr77co.js';
1
+ export { A as Adapter, j as AdditionalSessionFieldsInput, k as AdditionalSessionFieldsOutput, h as AdditionalUserFieldsInput, i as AdditionalUserFieldsOutput, a as Auth, p as AuthContext, s as BetterAuthCookies, B as BetterAuthOptions, b as BetterAuthPlugin, E as EligibleCookies, G as GenericEndpointContext, H as HookEndpointContext, m as InferPluginTypes, l as InferSession, I as InferUser, P as PluginSchema, R as RateLimit, S as SecondaryStorage, W as Where, g as betterAuth, r as createCookieGetter, x as createLogger, u as deleteSessionCookie, q as getCookies, n as init, y as logger, w as parseCookies, v as parseSetCookieHeader, t as setSessionCookie } from './auth-BTj2ofMy.js';
2
2
  export { D as DeepPartial, H as HasRequiredKeys, L as LiteralString, a as LiteralUnion, P as Prettify, R as RequiredKeysOf, S as StripEmptyObjects, U as UnionToIntersection, W as WithoutEmpty } from './helper-DPDj8Nix.js';
3
3
  export { AtomListener, BetterAuthClientPlugin, ClientOptions, InferActions, InferAdditionalFromClient, InferClientAPI, InferPluginsFromClient, InferSessionFromClient, InferUserFromClient, IsSignal } from './types.js';
4
4
  export { H as HIDE_METADATA } from './hide-metadata-DEHJp1rk.js';