@payez/next-mvp 4.0.41 → 4.0.42

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.
@@ -22,13 +22,21 @@ export interface BetterAuthSocialProvider {
22
22
  * Build Better Auth social providers from IDP config.
23
23
  */
24
24
  export declare function buildBetterAuthProviders(config: IDPClientConfig): Record<string, BetterAuthSocialProvider>;
25
+ /**
26
+ * Optional extra plugins for createBetterAuthInstance.
27
+ * Use to add credentials/custom signin endpoints from the host app.
28
+ */
29
+ export type BetterAuthExtraPlugins = any[];
25
30
  /**
26
31
  * Create Better Auth instance from IDP config.
27
32
  *
28
33
  * No database — runs in stateless mode with JWE cookie cache.
29
34
  * Call after getIDPClientConfig() resolves.
35
+ *
36
+ * @param idpConfig IDP client config (from getIDPClientConfig)
37
+ * @param extraPlugins Optional plugins to add (e.g., credentials plugin from host app)
30
38
  */
31
- export declare function createBetterAuthInstance(idpConfig: IDPClientConfig): import("better-auth").Auth<{
39
+ export declare function createBetterAuthInstance(idpConfig: IDPClientConfig, extraPlugins?: BetterAuthExtraPlugins): import("better-auth").Auth<{
32
40
  baseURL: string;
33
41
  secret: string;
34
42
  socialProviders: Record<string, BetterAuthSocialProvider>;
@@ -53,7 +61,7 @@ export declare function createBetterAuthInstance(idpConfig: IDPClientConfig): im
53
61
  };
54
62
  };
55
63
  };
56
- plugins: [{
64
+ plugins: [...any[], {
57
65
  id: "next-cookies";
58
66
  hooks: {
59
67
  before: {
@@ -77,7 +85,7 @@ export declare function isBetterAuthEnabled(): boolean;
77
85
  */
78
86
  declare let cachedInstance: any;
79
87
  export { cachedInstance as __betterAuthInstance };
80
- export declare function getBetterAuthInstance(): Promise<any>;
88
+ export declare function getBetterAuthInstance(extraPlugins?: BetterAuthExtraPlugins): Promise<any>;
81
89
  /**
82
90
  * Get flag-gated auth handler for Next.js route.
83
91
  *
@@ -80,8 +80,11 @@ function buildBetterAuthProviders(config) {
80
80
  *
81
81
  * No database — runs in stateless mode with JWE cookie cache.
82
82
  * Call after getIDPClientConfig() resolves.
83
+ *
84
+ * @param idpConfig IDP client config (from getIDPClientConfig)
85
+ * @param extraPlugins Optional plugins to add (e.g., credentials plugin from host app)
83
86
  */
84
- function createBetterAuthInstance(idpConfig) {
87
+ function createBetterAuthInstance(idpConfig, extraPlugins = []) {
85
88
  const appSlug = idpConfig.clientSlug || (0, app_slug_1.getAppSlug)();
86
89
  // Resolve base URL: BETTER_AUTH_URL env > IDP config > localhost fallback
87
90
  // Must include /api/auth since that's where the catch-all route is mounted
@@ -148,6 +151,7 @@ function createBetterAuthInstance(idpConfig) {
148
151
  },
149
152
  },
150
153
  plugins: [
154
+ ...extraPlugins,
151
155
  (0, next_js_1.nextCookies)(),
152
156
  ],
153
157
  });
@@ -167,12 +171,12 @@ let cachedInstance = null;
167
171
  exports.__betterAuthInstance = cachedInstance;
168
172
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
173
  let initPromise = null;
170
- async function getBetterAuthInstance() {
174
+ async function getBetterAuthInstance(extraPlugins = []) {
171
175
  if (cachedInstance)
172
176
  return cachedInstance;
173
177
  if (!initPromise) {
174
178
  initPromise = (0, idp_client_config_1.getIDPClientConfig)(true).then(config => {
175
- const instance = createBetterAuthInstance(config);
179
+ const instance = createBetterAuthInstance(config, extraPlugins);
176
180
  exports.__betterAuthInstance = cachedInstance = instance;
177
181
  console.log('[BETTER_AUTH] Instance created for', config.clientSlug || config.clientId);
178
182
  return instance;
@@ -36,7 +36,7 @@ export declare function getAuthInstance(): Promise<import("better-auth/types").A
36
36
  };
37
37
  };
38
38
  };
39
- plugins: [{
39
+ plugins: [...any[], {
40
40
  id: "next-cookies";
41
41
  hooks: {
42
42
  before: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payez/next-mvp",
3
- "version": "4.0.41",
3
+ "version": "4.0.42",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,13 +48,23 @@ export function buildBetterAuthProviders(
48
48
  return providers;
49
49
  }
50
50
 
51
+ /**
52
+ * Optional extra plugins for createBetterAuthInstance.
53
+ * Use to add credentials/custom signin endpoints from the host app.
54
+ */
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ export type BetterAuthExtraPlugins = any[];
57
+
51
58
  /**
52
59
  * Create Better Auth instance from IDP config.
53
60
  *
54
61
  * No database — runs in stateless mode with JWE cookie cache.
55
62
  * Call after getIDPClientConfig() resolves.
63
+ *
64
+ * @param idpConfig IDP client config (from getIDPClientConfig)
65
+ * @param extraPlugins Optional plugins to add (e.g., credentials plugin from host app)
56
66
  */
57
- export function createBetterAuthInstance(idpConfig: IDPClientConfig) {
67
+ export function createBetterAuthInstance(idpConfig: IDPClientConfig, extraPlugins: BetterAuthExtraPlugins = []) {
58
68
  const appSlug = idpConfig.clientSlug || getAppSlug();
59
69
 
60
70
  // Resolve base URL: BETTER_AUTH_URL env > IDP config > localhost fallback
@@ -123,6 +133,7 @@ export function createBetterAuthInstance(idpConfig: IDPClientConfig) {
123
133
  },
124
134
 
125
135
  plugins: [
136
+ ...extraPlugins,
126
137
  nextCookies(),
127
138
  ],
128
139
  });
@@ -148,12 +159,12 @@ let initPromise: Promise<any> | null = null;
148
159
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
149
160
  export { cachedInstance as __betterAuthInstance };
150
161
 
151
- export async function getBetterAuthInstance() {
162
+ export async function getBetterAuthInstance(extraPlugins: BetterAuthExtraPlugins = []) {
152
163
  if (cachedInstance) return cachedInstance;
153
164
 
154
165
  if (!initPromise) {
155
166
  initPromise = getIDPClientConfig(true).then(config => {
156
- const instance = createBetterAuthInstance(config);
167
+ const instance = createBetterAuthInstance(config, extraPlugins);
157
168
  cachedInstance = instance;
158
169
  console.log('[BETTER_AUTH] Instance created for', config.clientSlug || config.clientId);
159
170
  return instance;