better-auth 0.4.1 → 0.4.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.
package/dist/plugins.js CHANGED
@@ -40,9 +40,10 @@ import { generateCodeVerifier } from "oslo/oauth2";
40
40
  import { z as z3 } from "zod";
41
41
 
42
42
  // src/social-providers/apple.ts
43
- import "arctic";
44
43
  import { parseJWT } from "oslo/jwt";
45
- import "@better-fetch/fetch";
44
+
45
+ // src/social-providers/utils.ts
46
+ import { OAuth2Tokens } from "arctic";
46
47
 
47
48
  // src/error/better-auth-error.ts
48
49
  var BetterAuthError = class extends Error {
@@ -55,9 +56,6 @@ var BetterAuthError = class extends Error {
55
56
  }
56
57
  };
57
58
 
58
- // src/social-providers/utils.ts
59
- import { OAuth2Tokens } from "arctic";
60
-
61
59
  // src/utils/base-url.ts
62
60
  function checkHasPath(url) {
63
61
  try {
@@ -138,7 +136,15 @@ function generateCodeChallenge(codeVerifier) {
138
136
  includePadding: false
139
137
  });
140
138
  }
141
- function createAuthorizationURL(id, options, authorizationEndpoint, state, codeVerifier, scopes, disablePkce) {
139
+ function createAuthorizationURL({
140
+ id,
141
+ options,
142
+ authorizationEndpoint,
143
+ state,
144
+ codeVerifier,
145
+ scopes,
146
+ disablePkce
147
+ }) {
142
148
  const url = new URL(authorizationEndpoint);
143
149
  url.searchParams.set("response_type", "code");
144
150
  url.searchParams.set("client_id", options.clientId);
@@ -148,7 +154,7 @@ function createAuthorizationURL(id, options, authorizationEndpoint, state, codeV
148
154
  "redirect_uri",
149
155
  options.redirectURI || getRedirectURI(id)
150
156
  );
151
- if (!disablePkce) {
157
+ if (!disablePkce && codeVerifier) {
152
158
  const codeChallenge = generateCodeChallenge(codeVerifier);
153
159
  url.searchParams.set("code_challenge_method", "S256");
154
160
  url.searchParams.set("code_challenge", codeChallenge);
@@ -196,7 +202,7 @@ var apple = (options) => {
196
202
  };
197
203
 
198
204
  // src/social-providers/discord.ts
199
- import { betterFetch as betterFetch3 } from "@better-fetch/fetch";
205
+ import { betterFetch as betterFetch2 } from "@better-fetch/fetch";
200
206
  var discord = (options) => {
201
207
  return {
202
208
  id: "discord",
@@ -220,7 +226,7 @@ var discord = (options) => {
220
226
  });
221
227
  },
222
228
  async getUserInfo(token) {
223
- const { data: profile, error: error2 } = await betterFetch3(
229
+ const { data: profile, error: error2 } = await betterFetch2(
224
230
  "https://discord.com/api/users/@me",
225
231
  {
226
232
  headers: {
@@ -253,20 +259,21 @@ var discord = (options) => {
253
259
  };
254
260
 
255
261
  // src/social-providers/facebook.ts
256
- import { betterFetch as betterFetch4 } from "@better-fetch/fetch";
257
- import { Facebook } from "arctic";
262
+ import { betterFetch as betterFetch3 } from "@better-fetch/fetch";
258
263
  var facebook = (options) => {
259
- const facebookArctic = new Facebook(
260
- options.clientId,
261
- options.clientSecret,
262
- getRedirectURI("facebook", options.redirectURI)
263
- );
264
264
  return {
265
265
  id: "facebook",
266
266
  name: "Facebook",
267
- createAuthorizationURL({ state, scopes }) {
267
+ createAuthorizationURL({ state, scopes, codeVerifier }) {
268
268
  const _scopes = options.scope || scopes || ["email", "public_profile"];
269
- return facebookArctic.createAuthorizationURL(state, _scopes);
269
+ return createAuthorizationURL({
270
+ id: "facebook",
271
+ options,
272
+ authorizationEndpoint: "https://www.facebook.com/v16.0/dialog/oauth",
273
+ scopes: _scopes,
274
+ state,
275
+ codeVerifier
276
+ });
270
277
  },
271
278
  validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
272
279
  return validateAuthorizationCode({
@@ -278,7 +285,7 @@ var facebook = (options) => {
278
285
  });
279
286
  },
280
287
  async getUserInfo(token) {
281
- const { data: profile, error: error2 } = await betterFetch4(
288
+ const { data: profile, error: error2 } = await betterFetch3(
282
289
  "https://graph.facebook.com/me",
283
290
  {
284
291
  auth: {
@@ -304,21 +311,22 @@ var facebook = (options) => {
304
311
  };
305
312
 
306
313
  // src/social-providers/github.ts
307
- import { betterFetch as betterFetch5 } from "@better-fetch/fetch";
308
- import { GitHub } from "arctic";
314
+ import { betterFetch as betterFetch4 } from "@better-fetch/fetch";
309
315
  var github = (options) => {
310
- const githubArctic = new GitHub(
311
- options.clientId,
312
- options.clientSecret,
313
- getRedirectURI("github", options.redirectURI)
314
- );
315
316
  const tokenEndpoint = "https://github.com/login/oauth/access_token";
316
317
  return {
317
318
  id: "github",
318
319
  name: "Github",
319
- createAuthorizationURL({ state, scopes }) {
320
+ createAuthorizationURL({ state, scopes, codeVerifier }) {
320
321
  const _scopes = options.scope || scopes || ["user:email"];
321
- return githubArctic.createAuthorizationURL(state, _scopes);
322
+ return createAuthorizationURL({
323
+ id: "github",
324
+ options,
325
+ authorizationEndpoint: "https://github.com/login/oauth/authorize",
326
+ scopes: _scopes,
327
+ state,
328
+ codeVerifier
329
+ });
322
330
  },
323
331
  validateAuthorizationCode: async (code, _, redirect) => {
324
332
  return validateAuthorizationCode({
@@ -329,7 +337,7 @@ var github = (options) => {
329
337
  });
330
338
  },
331
339
  async getUserInfo(token) {
332
- const { data: profile, error: error2 } = await betterFetch5(
340
+ const { data: profile, error: error2 } = await betterFetch4(
333
341
  "https://api.github.com/user",
334
342
  {
335
343
  auth: {
@@ -343,7 +351,7 @@ var github = (options) => {
343
351
  }
344
352
  let emailVerified = false;
345
353
  if (!profile.email) {
346
- const { data, error: error3 } = await betterFetch5("https://api.github.com/user/emails", {
354
+ const { data, error: error3 } = await betterFetch4("https://api.github.com/user/emails", {
347
355
  auth: {
348
356
  type: "Bearer",
349
357
  token: token.accessToken()
@@ -369,7 +377,6 @@ var github = (options) => {
369
377
  };
370
378
 
371
379
  // src/social-providers/google.ts
372
- import { Google } from "arctic";
373
380
  import { parseJWT as parseJWT2 } from "oslo/jwt";
374
381
 
375
382
  // src/utils/logger.ts
@@ -416,11 +423,6 @@ var logger = createLogger();
416
423
 
417
424
  // src/social-providers/google.ts
418
425
  var google = (options) => {
419
- const googleArctic = new Google(
420
- options.clientId,
421
- options.clientSecret,
422
- getRedirectURI("google", options.redirectURI)
423
- );
424
426
  return {
425
427
  id: "google",
426
428
  name: "Google",
@@ -435,11 +437,14 @@ var google = (options) => {
435
437
  throw new BetterAuthError("codeVerifier is required for Google");
436
438
  }
437
439
  const _scopes = options.scope || scopes || ["email", "profile"];
438
- const url = googleArctic.createAuthorizationURL(
440
+ const url = createAuthorizationURL({
441
+ id: "google",
442
+ options,
443
+ authorizationEndpoint: "https://accounts.google.com/o/oauth2/auth",
444
+ scopes: _scopes,
439
445
  state,
440
- codeVerifier,
441
- _scopes
442
- );
446
+ codeVerifier
447
+ });
443
448
  return url;
444
449
  },
445
450
  validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
@@ -471,7 +476,7 @@ var google = (options) => {
471
476
  };
472
477
 
473
478
  // src/social-providers/microsoft-entra-id.ts
474
- import { betterFetch as betterFetch6 } from "@better-fetch/fetch";
479
+ import { betterFetch as betterFetch5 } from "@better-fetch/fetch";
475
480
  import { parseJWT as parseJWT3 } from "oslo/jwt";
476
481
  var microsoft = (options) => {
477
482
  const tenant = options.tenantId || "common";
@@ -482,14 +487,14 @@ var microsoft = (options) => {
482
487
  name: "Microsoft EntraID",
483
488
  createAuthorizationURL(data) {
484
489
  const scopes = options.scope || data.scopes || ["openid", "profile", "email", "User.Read"];
485
- return createAuthorizationURL(
486
- "microsoft",
490
+ return createAuthorizationURL({
491
+ id: "microsoft",
487
492
  options,
488
493
  authorizationEndpoint,
489
- data.state,
490
- data.codeVerifier,
494
+ state: data.state,
495
+ codeVerifier: data.codeVerifier,
491
496
  scopes
492
- );
497
+ });
493
498
  },
494
499
  validateAuthorizationCode(code, codeVerifier, redirectURI) {
495
500
  return validateAuthorizationCode({
@@ -503,7 +508,7 @@ var microsoft = (options) => {
503
508
  async getUserInfo(token) {
504
509
  const user = parseJWT3(token.idToken())?.payload;
505
510
  const profilePhotoSize = options.profilePhotoSize || 48;
506
- await betterFetch6(
511
+ await betterFetch5(
507
512
  `https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
508
513
  {
509
514
  headers: {
@@ -539,20 +544,21 @@ var microsoft = (options) => {
539
544
  };
540
545
 
541
546
  // src/social-providers/spotify.ts
542
- import { betterFetch as betterFetch7 } from "@better-fetch/fetch";
543
- import { Spotify } from "arctic";
547
+ import { betterFetch as betterFetch6 } from "@better-fetch/fetch";
544
548
  var spotify = (options) => {
545
- const spotifyArctic = new Spotify(
546
- options.clientId,
547
- options.clientSecret,
548
- getRedirectURI("spotify", options.redirectURI)
549
- );
550
549
  return {
551
550
  id: "spotify",
552
551
  name: "Spotify",
553
- createAuthorizationURL({ state, scopes }) {
552
+ createAuthorizationURL({ state, scopes, codeVerifier }) {
554
553
  const _scopes = options.scope || scopes || ["user-read-email"];
555
- return spotifyArctic.createAuthorizationURL(state, _scopes);
554
+ return createAuthorizationURL({
555
+ id: "spotify",
556
+ options,
557
+ authorizationEndpoint: "https://accounts.spotify.com/authorize",
558
+ scopes: _scopes,
559
+ state,
560
+ codeVerifier
561
+ });
556
562
  },
557
563
  validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
558
564
  return validateAuthorizationCode({
@@ -564,7 +570,7 @@ var spotify = (options) => {
564
570
  });
565
571
  },
566
572
  async getUserInfo(token) {
567
- const { data: profile, error: error2 } = await betterFetch7(
573
+ const { data: profile, error: error2 } = await betterFetch6(
568
574
  "https://api.spotify.com/v1/me",
569
575
  {
570
576
  method: "GET",
@@ -591,20 +597,20 @@ var spotify = (options) => {
591
597
  };
592
598
 
593
599
  // src/social-providers/twitch.ts
594
- import { betterFetch as betterFetch8 } from "@better-fetch/fetch";
595
- import { Twitch } from "arctic";
600
+ import { betterFetch as betterFetch7 } from "@better-fetch/fetch";
596
601
  var twitch = (options) => {
597
- const twitchArctic = new Twitch(
598
- options.clientId,
599
- options.clientSecret,
600
- getRedirectURI("twitch", options.redirectURI)
601
- );
602
602
  return {
603
603
  id: "twitch",
604
604
  name: "Twitch",
605
605
  createAuthorizationURL({ state, scopes }) {
606
606
  const _scopes = options.scope || scopes || ["activity:write", "read"];
607
- return twitchArctic.createAuthorizationURL(state, _scopes);
607
+ return createAuthorizationURL({
608
+ id: "twitch",
609
+ options,
610
+ authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
611
+ scopes: _scopes,
612
+ state
613
+ });
608
614
  },
609
615
  validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
610
616
  return validateAuthorizationCode({
@@ -615,7 +621,7 @@ var twitch = (options) => {
615
621
  });
616
622
  },
617
623
  async getUserInfo(token) {
618
- const { data: profile, error: error2 } = await betterFetch8(
624
+ const { data: profile, error: error2 } = await betterFetch7(
619
625
  "https://api.twitch.tv/helix/users",
620
626
  {
621
627
  method: "GET",
@@ -642,24 +648,21 @@ var twitch = (options) => {
642
648
  };
643
649
 
644
650
  // src/social-providers/twitter.ts
645
- import { betterFetch as betterFetch9 } from "@better-fetch/fetch";
646
- import { Twitter } from "arctic";
651
+ import { betterFetch as betterFetch8 } from "@better-fetch/fetch";
647
652
  var twitter = (options) => {
648
- const twitterArctic = new Twitter(
649
- options.clientId,
650
- options.clientSecret,
651
- getRedirectURI("twitter", options.redirectURI)
652
- );
653
653
  return {
654
654
  id: "twitter",
655
655
  name: "Twitter",
656
656
  createAuthorizationURL(data) {
657
657
  const _scopes = options.scope || data.scopes || ["account_info.read"];
658
- return twitterArctic.createAuthorizationURL(
659
- data.state,
660
- data.codeVerifier,
661
- _scopes
662
- );
658
+ return createAuthorizationURL({
659
+ id: "twitter",
660
+ options,
661
+ authorizationEndpoint: "https://twitter.com/i/oauth2/authorize",
662
+ scopes: _scopes,
663
+ state: data.state,
664
+ codeVerifier: data.codeVerifier
665
+ });
663
666
  },
664
667
  validateAuthorizationCode: async (code, codeVerifier, redirectURI) => {
665
668
  return validateAuthorizationCode({
@@ -671,7 +674,7 @@ var twitter = (options) => {
671
674
  });
672
675
  },
673
676
  async getUserInfo(token) {
674
- const { data: profile, error: error2 } = await betterFetch9(
677
+ const { data: profile, error: error2 } = await betterFetch8(
675
678
  "https://api.x.com/2/users/me?user.fields=profile_image_url",
676
679
  {
677
680
  method: "GET",
@@ -4573,7 +4576,7 @@ import { createFetch } from "@better-fetch/fetch";
4573
4576
  import "nanostores";
4574
4577
 
4575
4578
  // src/client/fetch-plugins.ts
4576
- import { betterFetch as betterFetch10 } from "@better-fetch/fetch";
4579
+ import { betterFetch as betterFetch9 } from "@better-fetch/fetch";
4577
4580
 
4578
4581
  // src/client/session-atom.ts
4579
4582
  import { atom as atom2 } from "nanostores";
package/dist/react.d.ts CHANGED
@@ -3,9 +3,9 @@ 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-C6jmDLjB.js';
6
+ import './index-C-85i2-P.js';
7
7
  import 'kysely';
8
- import './types-Bs23H3QM.js';
8
+ import './types-DoyeJ_dw.js';
9
9
  import 'arctic';
10
10
  import 'better-call';
11
11
  import 'better-sqlite3';
package/dist/social.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { j as AppleOptions, i as AppleProfile, n as DiscordOptions, D as DiscordProfile, v as FacebookOptions, F as FacebookProfile, d as GithubOptions, G as GithubProfile, f as GoogleOptions, e as GoogleProfile, M as MicrosoftEntraIDProfile, l as MicrosoftOptions, O as OAuthProvider, b as OAuthProviderList, P as ProviderOptions, a as SocialProviders, r as SpotifyOptions, q as SpotifyProfile, t as TwitchOptions, T as TwitchProfile, y as TwitterOption, x as TwitterProfile, k as apple, p as discord, w as facebook, g as github, h as google, m as microsoft, c as oAuthProviderList, o as oAuthProviders, s as spotify, u as twitch, z as twitter } from './types-Bs23H3QM.js';
1
+ export { j as AppleOptions, i as AppleProfile, n as DiscordOptions, D as DiscordProfile, v as FacebookOptions, F as FacebookProfile, d as GithubOptions, G as GithubProfile, f as GoogleOptions, e as GoogleProfile, M as MicrosoftEntraIDProfile, l as MicrosoftOptions, O as OAuthProvider, b as OAuthProviderList, P as ProviderOptions, a as SocialProviders, r as SpotifyOptions, q as SpotifyProfile, t as TwitchOptions, T as TwitchProfile, y as TwitterOption, x as TwitterProfile, k as apple, p as discord, w as facebook, g as github, h as google, m as microsoft, c as oAuthProviderList, o as oAuthProviders, s as spotify, u as twitch, z as twitter } from './types-DoyeJ_dw.js';
2
2
  import 'arctic';
3
3
  import './helper-DPDj8Nix.js';
4
4
  import 'zod';