better-auth 0.3.6 → 0.4.0

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.
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-Bh0h0nFa.js';
1
+ import { A as Adapter } from '../index-C6jmDLjB.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../types-Bs23H3QM.js';
@@ -1,5 +1,5 @@
1
1
  import { Db } from 'mongodb';
2
- import { W as Where } from '../index-Bh0h0nFa.js';
2
+ import { W as Where } from '../index-C6jmDLjB.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import '../types-Bs23H3QM.js';
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from '../index-Bh0h0nFa.js';
1
+ import { A as Adapter } from '../index-C6jmDLjB.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import '../types-Bs23H3QM.js';
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-Bh0h0nFa.js';
1
+ export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-C6jmDLjB.js';
2
2
  import './helper-DPDj8Nix.js';
3
3
  import 'zod';
4
4
  export { APIError } from 'better-call';
package/dist/api.js CHANGED
@@ -198,7 +198,7 @@ function generateCodeChallenge(codeVerifier) {
198
198
  includePadding: false
199
199
  });
200
200
  }
201
- function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes) {
201
+ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes, disablePkce) {
202
202
  const url = new URL(authorizationEndpoint);
203
203
  url.searchParams.set("response_type", "code");
204
204
  url.searchParams.set("client_id", options.clientId);
@@ -208,9 +208,11 @@ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeV
208
208
  "redirect_uri",
209
209
  options.redirectURI || getRedirectURI(id)
210
210
  );
211
- const codeChallenge = generateCodeChallenge(codeVerifier);
212
- url.searchParams.set("code_challenge_method", "S256");
213
- url.searchParams.set("code_challenge", codeChallenge);
211
+ if (!disablePkce) {
212
+ const codeChallenge = generateCodeChallenge(codeVerifier);
213
+ url.searchParams.set("code_challenge_method", "S256");
214
+ url.searchParams.set("code_challenge", codeChallenge);
215
+ }
214
216
  return url;
215
217
  }
216
218
 
@@ -778,14 +780,12 @@ var oAuthProviderList = Object.keys(oAuthProviders);
778
780
  // src/utils/state.ts
779
781
  import { generateState as generateStateOAuth } from "oslo/oauth2";
780
782
  import { z as z2 } from "zod";
781
- function generateState(callbackURL, currentURL, dontRememberMe, additionalFields) {
783
+ function generateState(callbackURL, currentURL) {
782
784
  const code = generateStateOAuth();
783
785
  const state = JSON.stringify({
784
786
  code,
785
787
  callbackURL,
786
- currentURL,
787
- dontRememberMe,
788
- additionalFields
788
+ currentURL
789
789
  });
790
790
  return { state, code };
791
791
  }
@@ -793,9 +793,7 @@ function parseState(state) {
793
793
  const data = z2.object({
794
794
  code: z2.string(),
795
795
  callbackURL: z2.string().optional(),
796
- currentURL: z2.string().optional(),
797
- dontRememberMe: z2.boolean().optional(),
798
- additionalFields: z2.record(z2.string()).optional()
796
+ currentURL: z2.string().optional()
799
797
  }).safeParse(JSON.parse(state));
800
798
  return data;
801
799
  }
@@ -1020,11 +1018,7 @@ var signInOAuth = createAuthEndpoint(
1020
1018
  /**
1021
1019
  * OAuth2 provider to use`
1022
1020
  */
1023
- provider: z4.enum(oAuthProviderList),
1024
- /**
1025
- * If this is true the session will only be valid for the current browser session
1026
- */
1027
- dontRememberMe: z4.boolean().default(false).optional()
1021
+ provider: z4.enum(oAuthProviderList)
1028
1022
  })
1029
1023
  },
1030
1024
  async (c) => {
@@ -1049,37 +1043,33 @@ var signInOAuth = createAuthEndpoint(
1049
1043
  callbackURL || currentURL?.origin || c.context.baseURL,
1050
1044
  c.query?.currentURL
1051
1045
  );
1052
- try {
1053
- await c.setSignedCookie(
1054
- cookie.state.name,
1055
- state.code,
1056
- c.context.secret,
1057
- cookie.state.options
1058
- );
1059
- const codeVerifier = generateCodeVerifier();
1060
- await c.setSignedCookie(
1061
- cookie.pkCodeVerifier.name,
1062
- codeVerifier,
1063
- c.context.secret,
1064
- cookie.pkCodeVerifier.options
1065
- );
1066
- const url = provider.createAuthorizationURL({
1067
- state: state.state,
1068
- codeVerifier
1069
- });
1070
- url.searchParams.set(
1071
- "redirect_uri",
1072
- `${c.context.baseURL}/callback/${c.body.provider}`
1073
- );
1074
- return {
1075
- url: url.toString(),
1076
- state: state.state,
1077
- codeVerifier,
1078
- redirect: true
1079
- };
1080
- } catch (e) {
1081
- throw new APIError3("INTERNAL_SERVER_ERROR");
1082
- }
1046
+ await c.setSignedCookie(
1047
+ cookie.state.name,
1048
+ state.code,
1049
+ c.context.secret,
1050
+ cookie.state.options
1051
+ );
1052
+ const codeVerifier = generateCodeVerifier();
1053
+ await c.setSignedCookie(
1054
+ cookie.pkCodeVerifier.name,
1055
+ codeVerifier,
1056
+ c.context.secret,
1057
+ cookie.pkCodeVerifier.options
1058
+ );
1059
+ const url = provider.createAuthorizationURL({
1060
+ state: state.state,
1061
+ codeVerifier
1062
+ });
1063
+ url.searchParams.set(
1064
+ "redirect_uri",
1065
+ `${c.context.baseURL}/callback/${c.body.provider}`
1066
+ );
1067
+ return c.json({
1068
+ url: url.toString(),
1069
+ state: state.state,
1070
+ codeVerifier,
1071
+ redirect: true
1072
+ });
1083
1073
  }
1084
1074
  );
1085
1075
  var signInEmail = createAuthEndpoint(
@@ -1373,14 +1363,14 @@ var callbackOAuth = createAuthEndpoint(
1373
1363
  );
1374
1364
  }
1375
1365
  const {
1376
- data: { callbackURL, currentURL, dontRememberMe, code }
1366
+ data: { callbackURL, currentURL, code: stateCode }
1377
1367
  } = parsedState;
1378
- const storedCode = await c.getSignedCookie(
1368
+ const storedState = await c.getSignedCookie(
1379
1369
  c.context.authCookies.state.name,
1380
1370
  c.context.secret
1381
1371
  );
1382
- if (storedCode !== code) {
1383
- logger.error("Oauth code mismatch", storedCode, code);
1372
+ if (storedState !== stateCode) {
1373
+ logger.error("OAuth state mismatch", storedState, stateCode);
1384
1374
  throw c.redirect(
1385
1375
  `${c.context.baseURL}/error?error=please_restart_the_process`
1386
1376
  );
@@ -1486,8 +1476,7 @@ var callbackOAuth = createAuthEndpoint(
1486
1476
  try {
1487
1477
  const session = await c.context.internalAdapter.createSession(
1488
1478
  userId || id,
1489
- c.request,
1490
- dontRememberMe
1479
+ c.request
1491
1480
  );
1492
1481
  if (!session) {
1493
1482
  const url = new URL(currentURL || callbackURL);
@@ -1495,7 +1484,7 @@ var callbackOAuth = createAuthEndpoint(
1495
1484
  throw c.redirect(url.toString());
1496
1485
  }
1497
1486
  try {
1498
- await setSessionCookie(c, session.id, dontRememberMe);
1487
+ await setSessionCookie(c, session.id);
1499
1488
  } catch (e) {
1500
1489
  c.context.logger.error("Unable to set session cookie", e);
1501
1490
  const url = new URL(currentURL || callbackURL);
@@ -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, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-DI8FMfhr.js';
6
- export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DI8FMfhr.js';
5
+ import { o as organization, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-DCBFTxDp.js';
6
+ export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-DCBFTxDp.js';
7
7
  import { P as Prettify } from '../helper-DPDj8Nix.js';
8
- import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-Bh0h0nFa.js';
8
+ import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-C6jmDLjB.js';
9
9
  import '../types-Bs23H3QM.js';
10
10
  import 'zod';
11
11
  import 'arctic';
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 './index-Bh0h0nFa.js';
9
+ import './index-C6jmDLjB.js';
10
10
  import 'kysely';
11
11
  import './types-Bs23H3QM.js';
12
12
  import 'arctic';
package/dist/client.js CHANGED
@@ -82,11 +82,6 @@ var csrfPlugin = {
82
82
  id: "csrf",
83
83
  name: "CSRF Check",
84
84
  async init(url, options) {
85
- if (!options?.baseURL) {
86
- throw new BetterAuthError(
87
- "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
88
- );
89
- }
90
85
  if (options?.method !== "GET") {
91
86
  options = options || {};
92
87
  const { data, error } = await betterFetch("/csrf", {
@@ -262,6 +262,7 @@ type AuthEndpoint = Endpoint<(ctx: {
262
262
  options: BetterAuthOptions;
263
263
  body: any;
264
264
  query: any;
265
+ params: any;
265
266
  headers: Headers;
266
267
  }) => Promise<EndpointResponse>>;
267
268
  type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
@@ -1174,19 +1175,13 @@ declare const signInOAuth: {
1174
1175
  /**
1175
1176
  * OAuth2 provider to use`
1176
1177
  */
1177
- provider: z.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1178
- /**
1179
- * If this is true the session will only be valid for the current browser session
1180
- */
1181
- dontRememberMe: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1178
+ provider: z.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
1182
1179
  }, "strip", z.ZodTypeAny, {
1183
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
1180
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
1184
1181
  callbackURL?: string | undefined;
1185
- dontRememberMe?: boolean | undefined;
1186
1182
  }, {
1187
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
1183
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
1188
1184
  callbackURL?: string | undefined;
1189
- dontRememberMe?: boolean | undefined;
1190
1185
  }>;
1191
1186
  }>]>(...ctx: C): Promise<C extends [{
1192
1187
  asResponse: true;
@@ -1219,19 +1214,13 @@ declare const signInOAuth: {
1219
1214
  /**
1220
1215
  * OAuth2 provider to use`
1221
1216
  */
1222
- provider: z.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
1223
- /**
1224
- * If this is true the session will only be valid for the current browser session
1225
- */
1226
- dontRememberMe: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
1217
+ provider: z.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
1227
1218
  }, "strip", z.ZodTypeAny, {
1228
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
1219
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
1229
1220
  callbackURL?: string | undefined;
1230
- dontRememberMe?: boolean | undefined;
1231
1221
  }, {
1232
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
1222
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
1233
1223
  callbackURL?: string | undefined;
1234
- dontRememberMe?: boolean | undefined;
1235
1224
  }>;
1236
1225
  };
1237
1226
  method: better_call.Method | better_call.Method[];
@@ -2447,16 +2436,13 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2447
2436
  }>>;
2448
2437
  body: zod.ZodObject<{
2449
2438
  callbackURL: zod.ZodOptional<zod.ZodString>;
2450
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2451
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
2439
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
2452
2440
  }, "strip", zod.ZodTypeAny, {
2453
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
2441
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
2454
2442
  callbackURL?: string | undefined;
2455
- dontRememberMe?: boolean | undefined;
2456
2443
  }, {
2457
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
2444
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
2458
2445
  callbackURL?: string | undefined;
2459
- dontRememberMe?: boolean | undefined;
2460
2446
  }>;
2461
2447
  }>]>(...ctx: C_1): Promise<C_1 extends [{
2462
2448
  asResponse: true;
@@ -2479,16 +2465,13 @@ declare function getEndpoints<C extends AuthContext, Option extends BetterAuthOp
2479
2465
  }>>;
2480
2466
  body: zod.ZodObject<{
2481
2467
  callbackURL: zod.ZodOptional<zod.ZodString>;
2482
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
2483
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
2468
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
2484
2469
  }, "strip", zod.ZodTypeAny, {
2485
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
2470
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
2486
2471
  callbackURL?: string | undefined;
2487
- dontRememberMe?: boolean | undefined;
2488
2472
  }, {
2489
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
2473
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
2490
2474
  callbackURL?: string | undefined;
2491
- dontRememberMe?: boolean | undefined;
2492
2475
  }>;
2493
2476
  };
2494
2477
  method: better_call.Method | better_call.Method[];
@@ -3562,16 +3545,13 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3562
3545
  }>>;
3563
3546
  body: zod.ZodObject<{
3564
3547
  callbackURL: zod.ZodOptional<zod.ZodString>;
3565
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3566
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
3548
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
3567
3549
  }, "strip", zod.ZodTypeAny, {
3568
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
3550
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
3569
3551
  callbackURL?: string | undefined;
3570
- dontRememberMe?: boolean | undefined;
3571
3552
  }, {
3572
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
3553
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
3573
3554
  callbackURL?: string | undefined;
3574
- dontRememberMe?: boolean | undefined;
3575
3555
  }>;
3576
3556
  }>]>(...ctx: C_1): Promise<C_1 extends [{
3577
3557
  asResponse: true;
@@ -3594,16 +3574,13 @@ declare const router: <C extends AuthContext, Option extends BetterAuthOptions>(
3594
3574
  }>>;
3595
3575
  body: zod.ZodObject<{
3596
3576
  callbackURL: zod.ZodOptional<zod.ZodString>;
3597
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
3598
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
3577
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
3599
3578
  }, "strip", zod.ZodTypeAny, {
3600
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
3579
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
3601
3580
  callbackURL?: string | undefined;
3602
- dontRememberMe?: boolean | undefined;
3603
3581
  }, {
3604
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
3582
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
3605
3583
  callbackURL?: string | undefined;
3606
- dontRememberMe?: boolean | undefined;
3607
3584
  }>;
3608
3585
  };
3609
3586
  method: better_call.Method | better_call.Method[];
@@ -4679,16 +4656,13 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
4679
4656
  }>>;
4680
4657
  body: zod.ZodObject<{
4681
4658
  callbackURL: zod.ZodOptional<zod.ZodString>;
4682
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4683
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
4659
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
4684
4660
  }, "strip", zod.ZodTypeAny, {
4685
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
4661
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
4686
4662
  callbackURL?: string | undefined;
4687
- dontRememberMe?: boolean | undefined;
4688
4663
  }, {
4689
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
4664
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
4690
4665
  callbackURL?: string | undefined;
4691
- dontRememberMe?: boolean | undefined;
4692
4666
  }>;
4693
4667
  }>]>(...ctx: C): Promise<C extends [{
4694
4668
  asResponse: true;
@@ -4711,16 +4685,13 @@ declare const betterAuth: <O extends BetterAuthOptions>(options: O) => {
4711
4685
  }>>;
4712
4686
  body: zod.ZodObject<{
4713
4687
  callbackURL: zod.ZodOptional<zod.ZodString>;
4714
- provider: zod.ZodEnum<["github", ...("github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter")[]]>;
4715
- dontRememberMe: zod.ZodOptional<zod.ZodDefault<zod.ZodBoolean>>;
4688
+ provider: zod.ZodEnum<["github", ...("apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter")[]]>;
4716
4689
  }, "strip", zod.ZodTypeAny, {
4717
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
4690
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
4718
4691
  callbackURL?: string | undefined;
4719
- dontRememberMe?: boolean | undefined;
4720
4692
  }, {
4721
- provider: "github" | "apple" | "discord" | "facebook" | "microsoft" | "google" | "spotify" | "twitch" | "twitter";
4693
+ provider: "apple" | "discord" | "facebook" | "github" | "google" | "microsoft" | "spotify" | "twitch" | "twitter";
4722
4694
  callbackURL?: string | undefined;
4723
- dontRememberMe?: boolean | undefined;
4724
4695
  }>;
4725
4696
  };
4726
4697
  method: better_call.Method | better_call.Method[];
@@ -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-Bh0h0nFa.js';
8
+ import { H as HookEndpointContext, g as AuthContext } from './index-C6jmDLjB.js';
9
9
  import * as nanostores from 'nanostores';
10
10
  import { atom } from 'nanostores';
11
11
  import * as _simplewebauthn_types from '@simplewebauthn/types';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Auth, a0 as betterAuth } from './index-Bh0h0nFa.js';
1
+ export { a as Auth, a0 as betterAuth } from './index-C6jmDLjB.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import './types-Bs23H3QM.js';
package/dist/index.js CHANGED
@@ -198,7 +198,7 @@ function generateCodeChallenge(codeVerifier) {
198
198
  includePadding: false
199
199
  });
200
200
  }
201
- function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes) {
201
+ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes, disablePkce) {
202
202
  const url = new URL(authorizationEndpoint);
203
203
  url.searchParams.set("response_type", "code");
204
204
  url.searchParams.set("client_id", options.clientId);
@@ -208,9 +208,11 @@ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeV
208
208
  "redirect_uri",
209
209
  options.redirectURI || getRedirectURI(id)
210
210
  );
211
- const codeChallenge = generateCodeChallenge(codeVerifier);
212
- url.searchParams.set("code_challenge_method", "S256");
213
- url.searchParams.set("code_challenge", codeChallenge);
211
+ if (!disablePkce) {
212
+ const codeChallenge = generateCodeChallenge(codeVerifier);
213
+ url.searchParams.set("code_challenge_method", "S256");
214
+ url.searchParams.set("code_challenge", codeChallenge);
215
+ }
214
216
  return url;
215
217
  }
216
218
 
@@ -778,14 +780,12 @@ var oAuthProviderList = Object.keys(oAuthProviders);
778
780
  // src/utils/state.ts
779
781
  import { generateState as generateStateOAuth } from "oslo/oauth2";
780
782
  import { z as z2 } from "zod";
781
- function generateState(callbackURL, currentURL, dontRememberMe, additionalFields) {
783
+ function generateState(callbackURL, currentURL) {
782
784
  const code = generateStateOAuth();
783
785
  const state = JSON.stringify({
784
786
  code,
785
787
  callbackURL,
786
- currentURL,
787
- dontRememberMe,
788
- additionalFields
788
+ currentURL
789
789
  });
790
790
  return { state, code };
791
791
  }
@@ -793,9 +793,7 @@ function parseState(state) {
793
793
  const data = z2.object({
794
794
  code: z2.string(),
795
795
  callbackURL: z2.string().optional(),
796
- currentURL: z2.string().optional(),
797
- dontRememberMe: z2.boolean().optional(),
798
- additionalFields: z2.record(z2.string()).optional()
796
+ currentURL: z2.string().optional()
799
797
  }).safeParse(JSON.parse(state));
800
798
  return data;
801
799
  }
@@ -816,7 +814,7 @@ function getCookies(options) {
816
814
  const secureCookiePrefix = secure ? "__Secure-" : "";
817
815
  const cookiePrefix = "better-auth";
818
816
  const sessionMaxAge = new TimeSpan(7, "d").seconds();
819
- const crossSubdomainEnabled = options.advanced?.crossSubDomainCookies?.enabled;
817
+ const crossSubdomainEnabled = !!options.advanced?.crossSubDomainCookies?.enabled;
820
818
  const domain = crossSubdomainEnabled ? options.advanced?.crossSubDomainCookies?.domain || (options.baseURL ? new URL(options.baseURL).hostname : void 0) : void 0;
821
819
  if (crossSubdomainEnabled && !domain) {
822
820
  throw new BetterAuthError(
@@ -833,7 +831,7 @@ function getCookies(options) {
833
831
  path: "/",
834
832
  secure: !!secureCookiePrefix,
835
833
  maxAge: sessionMaxAge,
836
- ...crossSubdomainEnabled && { domain }
834
+ ...crossSubdomainEnabled ? { domain } : {}
837
835
  }
838
836
  },
839
837
  csrfToken: {
@@ -844,7 +842,7 @@ function getCookies(options) {
844
842
  path: "/",
845
843
  secure: !!secureCookiePrefix,
846
844
  maxAge: 60 * 60 * 24 * 7,
847
- ...crossSubdomainEnabled && { domain }
845
+ ...crossSubdomainEnabled ? { domain } : {}
848
846
  }
849
847
  },
850
848
  state: {
@@ -855,8 +853,7 @@ function getCookies(options) {
855
853
  path: "/",
856
854
  secure: !!secureCookiePrefix,
857
855
  maxAge: 60 * 15,
858
- // 15 minutes in seconds
859
- ...crossSubdomainEnabled && { domain }
856
+ ...crossSubdomainEnabled ? { domain } : {}
860
857
  }
861
858
  },
862
859
  pkCodeVerifier: {
@@ -867,8 +864,7 @@ function getCookies(options) {
867
864
  path: "/",
868
865
  secure: !!secureCookiePrefix,
869
866
  maxAge: 60 * 15,
870
- // 15 minutes in seconds
871
- ...crossSubdomainEnabled && { domain }
867
+ ...crossSubdomainEnabled ? { domain } : {}
872
868
  }
873
869
  },
874
870
  dontRememberToken: {
@@ -879,7 +875,7 @@ function getCookies(options) {
879
875
  path: "/",
880
876
  secure: !!secureCookiePrefix,
881
877
  //no max age so it expires when the browser closes
882
- ...crossSubdomainEnabled && { domain }
878
+ ...crossSubdomainEnabled ? { domain } : {}
883
879
  }
884
880
  },
885
881
  nonce: {
@@ -890,14 +886,13 @@ function getCookies(options) {
890
886
  path: "/",
891
887
  secure: !!secureCookiePrefix,
892
888
  maxAge: 60 * 15,
893
- // 15 minutes in seconds
894
- ...crossSubdomainEnabled && { domain }
889
+ ...crossSubdomainEnabled ? { domain } : {}
895
890
  }
896
891
  }
897
892
  };
898
893
  }
899
894
  function createCookieGetter(options) {
900
- const secure = !!options.advanced?.useSecureCookies || process.env.NODE_ENV === "production";
895
+ const secure = options.advanced?.useSecureCookies !== void 0 ? options.advanced?.useSecureCookies : options.baseURL?.startsWith("https://") || process.env.NODE_ENV === "production";
901
896
  const secureCookiePrefix = secure ? "__Secure-" : "";
902
897
  const cookiePrefix = "better-auth";
903
898
  const domain = options.advanced?.crossSubDomainCookies?.domain || (options.baseURL ? new URL(options.baseURL).hostname : void 0);
@@ -914,7 +909,7 @@ function createCookieGetter(options) {
914
909
  maxAge: 60 * 15,
915
910
  // 15 minutes in seconds
916
911
  ...opts,
917
- ...crossSubdomainEnabled && { domain }
912
+ ...crossSubdomainEnabled ? { domain } : {}
918
913
  }
919
914
  };
920
915
  }
@@ -1129,11 +1124,7 @@ var signInOAuth = createAuthEndpoint(
1129
1124
  /**
1130
1125
  * OAuth2 provider to use`
1131
1126
  */
1132
- provider: z4.enum(oAuthProviderList),
1133
- /**
1134
- * If this is true the session will only be valid for the current browser session
1135
- */
1136
- dontRememberMe: z4.boolean().default(false).optional()
1127
+ provider: z4.enum(oAuthProviderList)
1137
1128
  })
1138
1129
  },
1139
1130
  async (c) => {
@@ -1158,37 +1149,33 @@ var signInOAuth = createAuthEndpoint(
1158
1149
  callbackURL || currentURL?.origin || c.context.baseURL,
1159
1150
  c.query?.currentURL
1160
1151
  );
1161
- try {
1162
- await c.setSignedCookie(
1163
- cookie.state.name,
1164
- state.code,
1165
- c.context.secret,
1166
- cookie.state.options
1167
- );
1168
- const codeVerifier = generateCodeVerifier();
1169
- await c.setSignedCookie(
1170
- cookie.pkCodeVerifier.name,
1171
- codeVerifier,
1172
- c.context.secret,
1173
- cookie.pkCodeVerifier.options
1174
- );
1175
- const url = provider.createAuthorizationURL({
1176
- state: state.state,
1177
- codeVerifier
1178
- });
1179
- url.searchParams.set(
1180
- "redirect_uri",
1181
- `${c.context.baseURL}/callback/${c.body.provider}`
1182
- );
1183
- return {
1184
- url: url.toString(),
1185
- state: state.state,
1186
- codeVerifier,
1187
- redirect: true
1188
- };
1189
- } catch (e) {
1190
- throw new APIError3("INTERNAL_SERVER_ERROR");
1191
- }
1152
+ await c.setSignedCookie(
1153
+ cookie.state.name,
1154
+ state.code,
1155
+ c.context.secret,
1156
+ cookie.state.options
1157
+ );
1158
+ const codeVerifier = generateCodeVerifier();
1159
+ await c.setSignedCookie(
1160
+ cookie.pkCodeVerifier.name,
1161
+ codeVerifier,
1162
+ c.context.secret,
1163
+ cookie.pkCodeVerifier.options
1164
+ );
1165
+ const url = provider.createAuthorizationURL({
1166
+ state: state.state,
1167
+ codeVerifier
1168
+ });
1169
+ url.searchParams.set(
1170
+ "redirect_uri",
1171
+ `${c.context.baseURL}/callback/${c.body.provider}`
1172
+ );
1173
+ return c.json({
1174
+ url: url.toString(),
1175
+ state: state.state,
1176
+ codeVerifier,
1177
+ redirect: true
1178
+ });
1192
1179
  }
1193
1180
  );
1194
1181
  var signInEmail = createAuthEndpoint(
@@ -1482,14 +1469,14 @@ var callbackOAuth = createAuthEndpoint(
1482
1469
  );
1483
1470
  }
1484
1471
  const {
1485
- data: { callbackURL, currentURL, dontRememberMe, code }
1472
+ data: { callbackURL, currentURL, code: stateCode }
1486
1473
  } = parsedState;
1487
- const storedCode = await c.getSignedCookie(
1474
+ const storedState = await c.getSignedCookie(
1488
1475
  c.context.authCookies.state.name,
1489
1476
  c.context.secret
1490
1477
  );
1491
- if (storedCode !== code) {
1492
- logger.error("Oauth code mismatch", storedCode, code);
1478
+ if (storedState !== stateCode) {
1479
+ logger.error("OAuth state mismatch", storedState, stateCode);
1493
1480
  throw c.redirect(
1494
1481
  `${c.context.baseURL}/error?error=please_restart_the_process`
1495
1482
  );
@@ -1595,8 +1582,7 @@ var callbackOAuth = createAuthEndpoint(
1595
1582
  try {
1596
1583
  const session = await c.context.internalAdapter.createSession(
1597
1584
  userId || id,
1598
- c.request,
1599
- dontRememberMe
1585
+ c.request
1600
1586
  );
1601
1587
  if (!session) {
1602
1588
  const url = new URL(currentURL || callbackURL);
@@ -1604,7 +1590,7 @@ var callbackOAuth = createAuthEndpoint(
1604
1590
  throw c.redirect(url.toString());
1605
1591
  }
1606
1592
  try {
1607
- await setSessionCookie(c, session.id, dontRememberMe);
1593
+ await setSessionCookie(c, session.id);
1608
1594
  } catch (e) {
1609
1595
  c.context.logger.error("Unable to set session cookie", e);
1610
1596
  const url = new URL(currentURL || callbackURL);
package/dist/next-js.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as Auth } from './index-Bh0h0nFa.js';
1
+ import { a as Auth } from './index-C6jmDLjB.js';
2
2
  import { U as User, S as Session } from './types-Bs23H3QM.js';
3
3
  import { NextRequest } from 'next/server';
4
4
  import 'zod';
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as http from 'http';
2
- import { a as Auth } from './index-Bh0h0nFa.js';
2
+ import { a as Auth } from './index-C6jmDLjB.js';
3
3
  import 'zod';
4
4
  import 'kysely';
5
5
  import './types-Bs23H3QM.js';
package/dist/plugins.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { A as AnonymousOptions, O as OrganizationOptions, b as Passkey, P as PasskeyOptions, U as UserWithPhoneNumber, f as UserWithRole, i as admin, h as adminMiddleware, e as anonymous, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-DI8FMfhr.js';
1
+ export { A as AnonymousOptions, O as OrganizationOptions, b as Passkey, P as PasskeyOptions, U as UserWithPhoneNumber, f as UserWithRole, i as admin, h as adminMiddleware, e as anonymous, g as getPasskeyActions, m as magicLink, o as organization, p as passkey, c as passkeyClient, d as phoneNumber, t as twoFactor, a as twoFactorClient, u as username } from './index-DCBFTxDp.js';
2
2
  export { i as ac } from './index-DfAHOgpj.js';
3
- import { H as HookEndpointContext } from './index-Bh0h0nFa.js';
4
- export { e as AuthEndpoint, f as AuthMiddleware, b as BetterAuthPlugin, P as PluginSchema, d as createAuthEndpoint, c as createAuthMiddleware, o as optionsMiddleware } from './index-Bh0h0nFa.js';
3
+ import { H as HookEndpointContext } from './index-C6jmDLjB.js';
4
+ export { e as AuthEndpoint, f as AuthMiddleware, b as BetterAuthPlugin, P as PluginSchema, d as createAuthEndpoint, c as createAuthMiddleware, o as optionsMiddleware } from './index-C6jmDLjB.js';
5
5
  import './types-Bs23H3QM.js';
6
6
  import 'zod';
7
7
  import 'arctic';
package/dist/plugins.js CHANGED
@@ -138,7 +138,7 @@ function generateCodeChallenge(codeVerifier) {
138
138
  includePadding: false
139
139
  });
140
140
  }
141
- function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes) {
141
+ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes, disablePkce) {
142
142
  const url = new URL(authorizationEndpoint);
143
143
  url.searchParams.set("response_type", "code");
144
144
  url.searchParams.set("client_id", options.clientId);
@@ -148,9 +148,11 @@ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeV
148
148
  "redirect_uri",
149
149
  options.redirectURI || getRedirectURI(id)
150
150
  );
151
- const codeChallenge = generateCodeChallenge(codeVerifier);
152
- url.searchParams.set("code_challenge_method", "S256");
153
- url.searchParams.set("code_challenge", codeChallenge);
151
+ if (!disablePkce) {
152
+ const codeChallenge = generateCodeChallenge(codeVerifier);
153
+ url.searchParams.set("code_challenge_method", "S256");
154
+ url.searchParams.set("code_challenge", codeChallenge);
155
+ }
154
156
  return url;
155
157
  }
156
158
 
@@ -718,14 +720,12 @@ var oAuthProviderList = Object.keys(oAuthProviders);
718
720
  // src/utils/state.ts
719
721
  import { generateState as generateStateOAuth } from "oslo/oauth2";
720
722
  import { z } from "zod";
721
- function generateState(callbackURL, currentURL, dontRememberMe, additionalFields) {
723
+ function generateState(callbackURL, currentURL) {
722
724
  const code = generateStateOAuth();
723
725
  const state = JSON.stringify({
724
726
  code,
725
727
  callbackURL,
726
- currentURL,
727
- dontRememberMe,
728
- additionalFields
728
+ currentURL
729
729
  });
730
730
  return { state, code };
731
731
  }
@@ -733,9 +733,7 @@ function parseState(state) {
733
733
  const data = z.object({
734
734
  code: z.string(),
735
735
  callbackURL: z.string().optional(),
736
- currentURL: z.string().optional(),
737
- dontRememberMe: z.boolean().optional(),
738
- additionalFields: z.record(z.string()).optional()
736
+ currentURL: z.string().optional()
739
737
  }).safeParse(JSON.parse(state));
740
738
  return data;
741
739
  }
@@ -941,11 +939,7 @@ var signInOAuth = createAuthEndpoint(
941
939
  /**
942
940
  * OAuth2 provider to use`
943
941
  */
944
- provider: z3.enum(oAuthProviderList),
945
- /**
946
- * If this is true the session will only be valid for the current browser session
947
- */
948
- dontRememberMe: z3.boolean().default(false).optional()
942
+ provider: z3.enum(oAuthProviderList)
949
943
  })
950
944
  },
951
945
  async (c) => {
@@ -970,37 +964,33 @@ var signInOAuth = createAuthEndpoint(
970
964
  callbackURL || currentURL?.origin || c.context.baseURL,
971
965
  c.query?.currentURL
972
966
  );
973
- try {
974
- await c.setSignedCookie(
975
- cookie.state.name,
976
- state.code,
977
- c.context.secret,
978
- cookie.state.options
979
- );
980
- const codeVerifier = generateCodeVerifier();
981
- await c.setSignedCookie(
982
- cookie.pkCodeVerifier.name,
983
- codeVerifier,
984
- c.context.secret,
985
- cookie.pkCodeVerifier.options
986
- );
987
- const url = provider.createAuthorizationURL({
988
- state: state.state,
989
- codeVerifier
990
- });
991
- url.searchParams.set(
992
- "redirect_uri",
993
- `${c.context.baseURL}/callback/${c.body.provider}`
994
- );
995
- return {
996
- url: url.toString(),
997
- state: state.state,
998
- codeVerifier,
999
- redirect: true
1000
- };
1001
- } catch (e) {
1002
- throw new APIError2("INTERNAL_SERVER_ERROR");
1003
- }
967
+ await c.setSignedCookie(
968
+ cookie.state.name,
969
+ state.code,
970
+ c.context.secret,
971
+ cookie.state.options
972
+ );
973
+ const codeVerifier = generateCodeVerifier();
974
+ await c.setSignedCookie(
975
+ cookie.pkCodeVerifier.name,
976
+ codeVerifier,
977
+ c.context.secret,
978
+ cookie.pkCodeVerifier.options
979
+ );
980
+ const url = provider.createAuthorizationURL({
981
+ state: state.state,
982
+ codeVerifier
983
+ });
984
+ url.searchParams.set(
985
+ "redirect_uri",
986
+ `${c.context.baseURL}/callback/${c.body.provider}`
987
+ );
988
+ return c.json({
989
+ url: url.toString(),
990
+ state: state.state,
991
+ codeVerifier,
992
+ redirect: true
993
+ });
1004
994
  }
1005
995
  );
1006
996
  var signInEmail = createAuthEndpoint(
@@ -1294,14 +1284,14 @@ var callbackOAuth = createAuthEndpoint(
1294
1284
  );
1295
1285
  }
1296
1286
  const {
1297
- data: { callbackURL, currentURL, dontRememberMe, code }
1287
+ data: { callbackURL, currentURL, code: stateCode }
1298
1288
  } = parsedState;
1299
- const storedCode = await c.getSignedCookie(
1289
+ const storedState = await c.getSignedCookie(
1300
1290
  c.context.authCookies.state.name,
1301
1291
  c.context.secret
1302
1292
  );
1303
- if (storedCode !== code) {
1304
- logger.error("Oauth code mismatch", storedCode, code);
1293
+ if (storedState !== stateCode) {
1294
+ logger.error("OAuth state mismatch", storedState, stateCode);
1305
1295
  throw c.redirect(
1306
1296
  `${c.context.baseURL}/error?error=please_restart_the_process`
1307
1297
  );
@@ -1407,8 +1397,7 @@ var callbackOAuth = createAuthEndpoint(
1407
1397
  try {
1408
1398
  const session = await c.context.internalAdapter.createSession(
1409
1399
  userId || id,
1410
- c.request,
1411
- dontRememberMe
1400
+ c.request
1412
1401
  );
1413
1402
  if (!session) {
1414
1403
  const url = new URL(currentURL || callbackURL);
@@ -1416,7 +1405,7 @@ var callbackOAuth = createAuthEndpoint(
1416
1405
  throw c.redirect(url.toString());
1417
1406
  }
1418
1407
  try {
1419
- await setSessionCookie(c, session.id, dontRememberMe);
1408
+ await setSessionCookie(c, session.id);
1420
1409
  } catch (e) {
1421
1410
  c.context.logger.error("Unable to set session cookie", e);
1422
1411
  const url = new URL(currentURL || callbackURL);
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _better_fetch_fetch from '@better-fetch/fetch';
3
3
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
4
4
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
5
5
  import { useStore } from '@nanostores/react';
6
- import './index-Bh0h0nFa.js';
6
+ import './index-C6jmDLjB.js';
7
7
  import 'kysely';
8
8
  import './types-Bs23H3QM.js';
9
9
  import 'arctic';
package/dist/react.js CHANGED
@@ -85,11 +85,6 @@ var csrfPlugin = {
85
85
  id: "csrf",
86
86
  name: "CSRF Check",
87
87
  async init(url, options) {
88
- if (!options?.baseURL) {
89
- throw new BetterAuthError(
90
- "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
91
- );
92
- }
93
88
  if (options?.method !== "GET") {
94
89
  options = options || {};
95
90
  const { data, error } = await betterFetch("/csrf", {
package/dist/social.js CHANGED
@@ -93,7 +93,7 @@ function generateCodeChallenge(codeVerifier) {
93
93
  includePadding: false
94
94
  });
95
95
  }
96
- function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes) {
96
+ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes, disablePkce) {
97
97
  const url = new URL(authorizationEndpoint);
98
98
  url.searchParams.set("response_type", "code");
99
99
  url.searchParams.set("client_id", options.clientId);
@@ -103,9 +103,11 @@ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeV
103
103
  "redirect_uri",
104
104
  options.redirectURI || getRedirectURI(id)
105
105
  );
106
- const codeChallenge = generateCodeChallenge(codeVerifier);
107
- url.searchParams.set("code_challenge_method", "S256");
108
- url.searchParams.set("code_challenge", codeChallenge);
106
+ if (!disablePkce) {
107
+ const codeChallenge = generateCodeChallenge(codeVerifier);
108
+ url.searchParams.set("code_challenge_method", "S256");
109
+ url.searchParams.set("code_challenge", codeChallenge);
110
+ }
109
111
  return url;
110
112
  }
111
113
 
@@ -1,4 +1,4 @@
1
- import { a as Auth } from './index-Bh0h0nFa.js';
1
+ import { a as Auth } from './index-C6jmDLjB.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import './types-Bs23H3QM.js';
package/dist/solid.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _better_fetch_fetch from '@better-fetch/fetch';
3
3
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
4
4
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
5
5
  import { Accessor } from 'solid-js';
6
- import './index-Bh0h0nFa.js';
6
+ import './index-C6jmDLjB.js';
7
7
  import 'kysely';
8
8
  import './types-Bs23H3QM.js';
9
9
  import 'arctic';
package/dist/solid.js CHANGED
@@ -85,11 +85,6 @@ var csrfPlugin = {
85
85
  id: "csrf",
86
86
  name: "CSRF Check",
87
87
  async init(url, options) {
88
- if (!options?.baseURL) {
89
- throw new BetterAuthError(
90
- "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
91
- );
92
- }
93
88
  if (options?.method !== "GET") {
94
89
  options = options || {};
95
90
  const { data, error } = await betterFetch("/csrf", {
@@ -1,4 +1,4 @@
1
- import { a as Auth, B as BetterAuthOptions } from './index-Bh0h0nFa.js';
1
+ import { a as Auth, B as BetterAuthOptions } from './index-C6jmDLjB.js';
2
2
  import 'zod';
3
3
  import 'kysely';
4
4
  import './types-Bs23H3QM.js';
package/dist/svelte.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as nanostores from 'nanostores';
3
3
  import * as _better_fetch_fetch from '@better-fetch/fetch';
4
4
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
5
5
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
6
- import './index-Bh0h0nFa.js';
6
+ import './index-C6jmDLjB.js';
7
7
  import 'kysely';
8
8
  import './types-Bs23H3QM.js';
9
9
  import 'arctic';
package/dist/svelte.js CHANGED
@@ -82,11 +82,6 @@ var csrfPlugin = {
82
82
  id: "csrf",
83
83
  name: "CSRF Check",
84
84
  async init(url, options) {
85
- if (!options?.baseURL) {
86
- throw new BetterAuthError(
87
- "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
88
- );
89
- }
90
85
  if (options?.method !== "GET") {
91
86
  options = options || {};
92
87
  const { data, error } = await betterFetch("/csrf", {
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as BetterAuthPlugin, a as Auth, I as InferFieldsInputClient, h as InferFieldsOutput } from './index-Bh0h0nFa.js';
2
- export { A as Adapter, k as AdditionalSessionFieldsInput, l as AdditionalSessionFieldsOutput, i as AdditionalUserFieldsInput, j as AdditionalUserFieldsOutput, g as AuthContext, B as BetterAuthOptions, G as GenericEndpointContext, H as HookEndpointContext, p as InferPluginTypes, n as InferSession, m as InferUser, P as PluginSchema, R as RateLimit, S as SecondaryStorage, W as Where, q as init } from './index-Bh0h0nFa.js';
1
+ import { b as BetterAuthPlugin, a as Auth, I as InferFieldsInputClient, h as InferFieldsOutput } from './index-C6jmDLjB.js';
2
+ export { A as Adapter, k as AdditionalSessionFieldsInput, l as AdditionalSessionFieldsOutput, i as AdditionalUserFieldsInput, j as AdditionalUserFieldsOutput, g as AuthContext, B as BetterAuthOptions, G as GenericEndpointContext, H as HookEndpointContext, p as InferPluginTypes, n as InferSession, m as InferUser, P as PluginSchema, R as RateLimit, S as SecondaryStorage, W as Where, q as init } from './index-C6jmDLjB.js';
3
3
  import { U as UnionToIntersection, H as HasRequiredKeys, P as Prettify, S as StripEmptyObjects, L as LiteralString } from './helper-DPDj8Nix.js';
4
4
  export { D as DeepPartial, a as LiteralUnion, R as RequiredKeysOf, W as WithoutEmpty } from './helper-DPDj8Nix.js';
5
5
  import { S as Session, U as User } from './types-Bs23H3QM.js';
package/dist/vue.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _better_fetch_fetch from '@better-fetch/fetch';
3
3
  import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
4
4
  import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
5
5
  import { Ref, DeepReadonly } from 'vue';
6
- import './index-Bh0h0nFa.js';
6
+ import './index-C6jmDLjB.js';
7
7
  import 'kysely';
8
8
  import './types-Bs23H3QM.js';
9
9
  import 'arctic';
package/dist/vue.js CHANGED
@@ -85,11 +85,6 @@ var csrfPlugin = {
85
85
  id: "csrf",
86
86
  name: "CSRF Check",
87
87
  async init(url, options) {
88
- if (!options?.baseURL) {
89
- throw new BetterAuthError(
90
- "API Base URL on the auth client isn't configured. Please pass it directly to the client `baseURL`"
91
- );
92
- }
93
88
  if (options?.method !== "GET") {
94
89
  options = options || {};
95
90
  const { data, error } = await betterFetch("/csrf", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "The most comprehensive authentication library for TypeScript.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,6 +55,7 @@
55
55
  "mongodb": "^6.9.0",
56
56
  "mysql2": "^3.11.0",
57
57
  "next": "^14.2.8",
58
+ "oauth2-mock-server": "^7.1.2",
58
59
  "pg": "^8.12.0",
59
60
  "prisma": "^5.19.1",
60
61
  "react": "^18.3.1",
@@ -81,7 +82,7 @@
81
82
  "@simplewebauthn/browser": "^10.0.0",
82
83
  "@simplewebauthn/server": "^10.0.1",
83
84
  "arctic": "2.0.0-next.9",
84
- "better-call": "0.2.5",
85
+ "better-call": "0.2.6",
85
86
  "c12": "^1.11.2",
86
87
  "chalk": "^5.3.0",
87
88
  "commander": "^12.1.0",