better-auth 0.4.4 → 0.4.6

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.
@@ -37,9 +37,22 @@ type zodKey<T> = isAny<T> extends true ? "any" : equals<T, boolean> extends true
37
37
  } ? "object" : "rest";
38
38
 
39
39
  type BetterAuthDbSchema = Record<string, {
40
+ /**
41
+ * The name of the table in the database
42
+ */
40
43
  tableName: string;
44
+ /**
45
+ * The fields of the table
46
+ */
41
47
  fields: Record<string, FieldAttribute>;
48
+ /**
49
+ * Whether to disable migrations for this table
50
+ * @default false
51
+ */
42
52
  disableMigrations?: boolean;
53
+ /**
54
+ * The order of the table
55
+ */
43
56
  order?: number;
44
57
  }>;
45
58
  declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDbSchema;
@@ -657,14 +670,12 @@ interface BetterAuthOptions {
657
670
  */
658
671
  sendResetPassword?: (url: string, user: User) => Promise<void>;
659
672
  /**
660
- * @param email the email to send the verification email to
661
- * @param url the url to send the verification
662
- * email to
663
- * @param token the actual token. You can use this
664
- * if you want to custom endpoint to verify the
665
- * email.
673
+ * @param user the user to send the verification email to
674
+ * @param url the url to send the verification email to
675
+ * it contains the token as well
676
+ * @param token the token to send the verification email to
666
677
  */
667
- sendVerificationEmail?: (email: string, url: string, token: string) => Promise<void>;
678
+ sendVerificationEmail?: (url: string, user: User, token: string) => Promise<void>;
668
679
  /**
669
680
  * Send a verification email automatically
670
681
  * after sign up
@@ -731,6 +742,18 @@ interface BetterAuthOptions {
731
742
  additionalFields?: {
732
743
  [key: string]: FieldAttribute;
733
744
  };
745
+ /**
746
+ * By default if secondary storage is provided
747
+ * the session is stored in the secondary storage.
748
+ *
749
+ * Set this to true to store the session in the database
750
+ * as well.
751
+ *
752
+ * Reads are always done from the secondary storage.
753
+ *
754
+ * @default false
755
+ */
756
+ storeSessionInDatabase?: boolean;
734
757
  };
735
758
  account?: {
736
759
  modelName?: string;
@@ -1004,13 +1027,13 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
1004
1027
  image?: string | undefined;
1005
1028
  }[]>;
1006
1029
  deleteUser: (userId: string) => Promise<void>;
1007
- createSession: (userId: string, request?: Request | Headers, dontRememberMe?: boolean, inputData?: Partial<Session> & Record<string, any>) => Promise<{
1030
+ createSession: (userId: string, request?: Request | Headers, dontRememberMe?: boolean, override?: Partial<Session> & Record<string, any>) => Promise<{
1008
1031
  id: string;
1009
1032
  userId: string;
1010
1033
  expiresAt: Date;
1011
1034
  ipAddress?: string | undefined;
1012
1035
  userAgent?: string | undefined;
1013
- } | null>;
1036
+ }>;
1014
1037
  findSession: (sessionId: string) => Promise<{
1015
1038
  session: Session;
1016
1039
  user: User;
@@ -1024,7 +1047,9 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
1024
1047
  } | null>;
1025
1048
  deleteSession: (id: string) => Promise<void>;
1026
1049
  deleteSessions: (userId: string) => Promise<void>;
1027
- findUserByEmail: (email: string) => Promise<{
1050
+ findUserByEmail: (email: string, options?: {
1051
+ includeAccounts: boolean;
1052
+ }) => Promise<{
1028
1053
  user: {
1029
1054
  id: string;
1030
1055
  email: string;
@@ -1064,7 +1089,7 @@ declare const createInternalAdapter: (adapter: Adapter, ctx: {
1064
1089
  idToken?: string | null | undefined;
1065
1090
  expiresAt?: Date | null | undefined;
1066
1091
  password?: string | null | undefined;
1067
- id?: string | undefined;
1092
+ id: string;
1068
1093
  } | null>;
1069
1094
  updateUser: (userId: string, data: Partial<User> & Record<string, any>) => Promise<{
1070
1095
  id: string;
@@ -1805,7 +1830,7 @@ declare const verifyEmail: {
1805
1830
  asResponse: true;
1806
1831
  }] ? Response : {
1807
1832
  status: boolean;
1808
- } | null>;
1833
+ }>;
1809
1834
  path: "/verify-email";
1810
1835
  options: {
1811
1836
  method: "GET";
@@ -2888,7 +2913,7 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2888
2913
  asResponse: true;
2889
2914
  }] ? Response : {
2890
2915
  status: boolean;
2891
- } | null>;
2916
+ }>;
2892
2917
  path: "/verify-email";
2893
2918
  options: {
2894
2919
  method: "GET";
@@ -3997,7 +4022,7 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3997
4022
  asResponse: true;
3998
4023
  }] ? Response : {
3999
4024
  status: boolean;
4000
- } | null>;
4025
+ }>;
4001
4026
  path: "/verify-email";
4002
4027
  options: {
4003
4028
  method: "GET";
@@ -5108,7 +5133,7 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
5108
5133
  asResponse: true;
5109
5134
  }] ? Response : {
5110
5135
  status: boolean;
5111
- } | null>;
5136
+ }>;
5112
5137
  path: "/verify-email";
5113
5138
  options: {
5114
5139
  method: "GET";
@@ -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, g as AuthContext } from './index-Bt0CUdx4.js';
8
+ import { H as HookEndpointContext, g as AuthContext } from './index-BJKlHmT9.js';
9
9
  import * as nanostores from 'nanostores';
10
10
  import { atom } from 'nanostores';
11
11
  import * as _simplewebauthn_types from '@simplewebauthn/types';
@@ -4777,11 +4777,61 @@ declare const adminMiddleware: better_call.Endpoint<better_call.Handler<string,
4777
4777
  };
4778
4778
  };
4779
4779
  }>, better_call.EndpointOptions>;
4780
- declare const admin: () => {
4780
+ interface AdminOptions {
4781
+ /**
4782
+ * The default role for a user created by the admin
4783
+ *
4784
+ * @default "user"
4785
+ */
4786
+ defaultRole?: string | false;
4787
+ /**
4788
+ * A default ban reason
4789
+ *
4790
+ * By default, no reason is provided
4791
+ */
4792
+ defaultBanReason?: string;
4793
+ /**
4794
+ * Number of seconds until the ban expires
4795
+ *
4796
+ * By default, the ban never expires
4797
+ */
4798
+ defaultBanExpiresIn?: number;
4799
+ /**
4800
+ * Duration of the impersonation session in seconds
4801
+ *
4802
+ * By default, the impersonation session lasts 1 hour
4803
+ */
4804
+ impersonationSessionDuration?: number;
4805
+ }
4806
+ declare const admin: (options?: AdminOptions) => {
4781
4807
  id: "admin";
4782
4808
  init(ctx: AuthContext): {
4783
4809
  options: {
4784
4810
  databaseHooks: {
4811
+ user: {
4812
+ create: {
4813
+ before(user: {
4814
+ id: string;
4815
+ email: string;
4816
+ emailVerified: boolean;
4817
+ name: string;
4818
+ createdAt: Date;
4819
+ updatedAt: Date;
4820
+ image?: string | undefined;
4821
+ }): Promise<{
4822
+ data: {
4823
+ id: string;
4824
+ email: string;
4825
+ emailVerified: boolean;
4826
+ name: string;
4827
+ createdAt: Date;
4828
+ updatedAt: Date;
4829
+ image?: string | undefined;
4830
+ role: string;
4831
+ };
4832
+ } | undefined>;
4833
+ };
4834
+ };
4785
4835
  session: {
4786
4836
  create: {
4787
4837
  before(session: {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Auth, a0 as betterAuth } from './index-Bt0CUdx4.js';
1
+ export { a as Auth, a0 as betterAuth } from './index-BJKlHmT9.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import './types-IzAbV4nB.js';