@better-auth/core 1.4.0-beta.9 → 1.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.
Files changed (151) hide show
  1. package/.turbo/turbo-build.log +41 -76
  2. package/dist/api/index.d.mts +3 -0
  3. package/dist/api/index.mjs +26 -0
  4. package/dist/async_hooks/index.d.mts +2 -10
  5. package/dist/async_hooks/index.mjs +2 -24
  6. package/dist/async_hooks-BfRfbd1J.mjs +18 -0
  7. package/dist/context/index.d.mts +54 -0
  8. package/dist/context/index.mjs +4 -0
  9. package/dist/context-DgQ9XGBl.mjs +114 -0
  10. package/dist/db/adapter/index.d.mts +3 -14
  11. package/dist/db/adapter/index.mjs +1 -1
  12. package/dist/db/index.d.mts +3 -39
  13. package/dist/db/index.mjs +46 -55
  14. package/dist/env/index.d.mts +2 -36
  15. package/dist/env/index.mjs +2 -299
  16. package/dist/env-DwlNAN_D.mjs +245 -0
  17. package/dist/error/index.d.mts +31 -29
  18. package/dist/error/index.mjs +3 -40
  19. package/dist/error-BhAKg8LX.mjs +45 -0
  20. package/dist/index-CdubV7uy.d.mts +82 -0
  21. package/dist/index-CkAWdKH8.d.mts +7352 -0
  22. package/dist/index-DgwIISs7.d.mts +7 -0
  23. package/dist/index.d.mts +3 -180
  24. package/dist/index.mjs +1 -1
  25. package/dist/oauth2/index.d.mts +3 -99
  26. package/dist/oauth2/index.mjs +2 -356
  27. package/dist/oauth2-DmgZmPEg.mjs +236 -0
  28. package/dist/social-providers/index.d.mts +3 -3903
  29. package/dist/social-providers/index.mjs +2434 -2654
  30. package/dist/utils/index.d.mts +5 -6
  31. package/dist/utils/index.mjs +2 -4
  32. package/dist/utils-C5EN75oV.mjs +7 -0
  33. package/package.json +70 -111
  34. package/src/api/index.ts +53 -0
  35. package/src/async_hooks/index.ts +1 -9
  36. package/src/context/endpoint-context.ts +49 -0
  37. package/src/context/index.ts +21 -0
  38. package/src/context/request-state.test.ts +94 -0
  39. package/src/context/request-state.ts +90 -0
  40. package/src/context/transaction.ts +73 -0
  41. package/src/db/adapter/index.ts +215 -129
  42. package/src/db/index.ts +12 -13
  43. package/src/db/plugin.ts +3 -3
  44. package/src/db/type.ts +54 -42
  45. package/src/env/color-depth.ts +5 -4
  46. package/src/env/env-impl.ts +2 -1
  47. package/src/env/index.ts +9 -9
  48. package/src/env/logger.test.ts +3 -2
  49. package/src/env/logger.ts +11 -9
  50. package/src/error/codes.ts +1 -1
  51. package/src/error/index.ts +1 -1
  52. package/src/oauth2/client-credentials-token.ts +9 -9
  53. package/src/oauth2/create-authorization-url.ts +12 -12
  54. package/src/oauth2/index.ts +10 -11
  55. package/src/oauth2/oauth-provider.ts +96 -74
  56. package/src/oauth2/refresh-access-token.ts +12 -12
  57. package/src/oauth2/utils.ts +2 -0
  58. package/src/oauth2/validate-authorization-code.ts +13 -15
  59. package/src/social-providers/apple.ts +8 -8
  60. package/src/social-providers/atlassian.ts +21 -19
  61. package/src/social-providers/cognito.ts +15 -15
  62. package/src/social-providers/discord.ts +8 -11
  63. package/src/social-providers/dropbox.ts +5 -5
  64. package/src/social-providers/facebook.ts +12 -10
  65. package/src/social-providers/figma.ts +6 -6
  66. package/src/social-providers/github.ts +4 -4
  67. package/src/social-providers/gitlab.ts +13 -10
  68. package/src/social-providers/google.ts +13 -13
  69. package/src/social-providers/huggingface.ts +27 -25
  70. package/src/social-providers/index.ts +30 -24
  71. package/src/social-providers/kakao.ts +41 -41
  72. package/src/social-providers/kick.ts +7 -9
  73. package/src/social-providers/line.ts +12 -12
  74. package/src/social-providers/linear.ts +9 -8
  75. package/src/social-providers/linkedin.ts +5 -5
  76. package/src/social-providers/microsoft-entra-id.ts +31 -15
  77. package/src/social-providers/naver.ts +5 -5
  78. package/src/social-providers/notion.ts +11 -9
  79. package/src/social-providers/paybin.ts +122 -0
  80. package/src/social-providers/paypal.ts +31 -29
  81. package/src/social-providers/polar.ts +110 -0
  82. package/src/social-providers/reddit.ts +6 -6
  83. package/src/social-providers/roblox.ts +15 -14
  84. package/src/social-providers/salesforce.ts +20 -18
  85. package/src/social-providers/slack.ts +4 -7
  86. package/src/social-providers/spotify.ts +5 -5
  87. package/src/social-providers/tiktok.ts +32 -33
  88. package/src/social-providers/twitch.ts +8 -8
  89. package/src/social-providers/twitter.ts +49 -45
  90. package/src/social-providers/vk.ts +14 -17
  91. package/src/social-providers/zoom.ts +29 -14
  92. package/src/types/context.ts +67 -67
  93. package/src/types/cookie.ts +1 -0
  94. package/src/types/index.ts +13 -11
  95. package/src/types/init-options.ts +1134 -911
  96. package/src/types/plugin-client.ts +61 -13
  97. package/src/types/plugin.ts +81 -57
  98. package/tsconfig.json +2 -5
  99. package/{build.config.ts → tsdown.config.ts} +8 -11
  100. package/vitest.config.ts +3 -0
  101. package/dist/async_hooks/index.cjs +0 -27
  102. package/dist/async_hooks/index.d.cts +0 -10
  103. package/dist/async_hooks/index.d.ts +0 -10
  104. package/dist/db/adapter/index.cjs +0 -2
  105. package/dist/db/adapter/index.d.cts +0 -14
  106. package/dist/db/adapter/index.d.ts +0 -14
  107. package/dist/db/index.cjs +0 -91
  108. package/dist/db/index.d.cts +0 -39
  109. package/dist/db/index.d.ts +0 -39
  110. package/dist/env/index.cjs +0 -315
  111. package/dist/env/index.d.cts +0 -36
  112. package/dist/env/index.d.ts +0 -36
  113. package/dist/error/index.cjs +0 -44
  114. package/dist/error/index.d.cts +0 -33
  115. package/dist/error/index.d.ts +0 -33
  116. package/dist/index.cjs +0 -2
  117. package/dist/index.d.cts +0 -180
  118. package/dist/index.d.ts +0 -180
  119. package/dist/middleware/index.cjs +0 -25
  120. package/dist/middleware/index.d.cts +0 -14
  121. package/dist/middleware/index.d.mts +0 -14
  122. package/dist/middleware/index.d.ts +0 -14
  123. package/dist/middleware/index.mjs +0 -21
  124. package/dist/oauth2/index.cjs +0 -368
  125. package/dist/oauth2/index.d.cts +0 -99
  126. package/dist/oauth2/index.d.ts +0 -99
  127. package/dist/shared/core.2rWMW9q9.d.ts +0 -13
  128. package/dist/shared/core.40VTWh-p.d.cts +0 -217
  129. package/dist/shared/core.BfcVdsSf.d.cts +0 -181
  130. package/dist/shared/core.Bisb2Bdk.d.mts +0 -181
  131. package/dist/shared/core.BwoNUcJQ.d.cts +0 -53
  132. package/dist/shared/core.BwoNUcJQ.d.mts +0 -53
  133. package/dist/shared/core.BwoNUcJQ.d.ts +0 -53
  134. package/dist/shared/core.CErFRCOZ.d.mts +0 -1684
  135. package/dist/shared/core.CGN6D-Mh.d.ts +0 -181
  136. package/dist/shared/core.CPuIItYE.d.ts +0 -217
  137. package/dist/shared/core.CftpHMDz.d.cts +0 -13
  138. package/dist/shared/core.Db7zJyxf.d.ts +0 -1684
  139. package/dist/shared/core.DqaxObkf.d.cts +0 -1684
  140. package/dist/shared/core.MjcDoj7R.d.cts +0 -5
  141. package/dist/shared/core.MjcDoj7R.d.mts +0 -5
  142. package/dist/shared/core.MjcDoj7R.d.ts +0 -5
  143. package/dist/shared/core.g2ZbxAEV.d.mts +0 -217
  144. package/dist/shared/core.g9ACQ8v2.d.mts +0 -13
  145. package/dist/social-providers/index.cjs +0 -2793
  146. package/dist/social-providers/index.d.cts +0 -3903
  147. package/dist/social-providers/index.d.ts +0 -3903
  148. package/dist/utils/index.cjs +0 -7
  149. package/dist/utils/index.d.cts +0 -10
  150. package/dist/utils/index.d.ts +0 -10
  151. package/src/middleware/index.ts +0 -33
@@ -1,20 +1,25 @@
1
1
  import type { LiteralString } from "../types";
2
2
 
3
3
  export interface OAuth2Tokens {
4
- tokenType?: string;
5
- accessToken?: string;
6
- refreshToken?: string;
7
- accessTokenExpiresAt?: Date;
8
- refreshTokenExpiresAt?: Date;
9
- scopes?: string[];
10
- idToken?: string;
4
+ tokenType?: string | undefined;
5
+ accessToken?: string | undefined;
6
+ refreshToken?: string | undefined;
7
+ accessTokenExpiresAt?: Date | undefined;
8
+ refreshTokenExpiresAt?: Date | undefined;
9
+ scopes?: string[] | undefined;
10
+ idToken?: string | undefined;
11
+ /**
12
+ * Raw token response from the provider.
13
+ * Preserves provider-specific fields that are not part of the standard OAuth2 token response.
14
+ */
15
+ raw?: Record<string, unknown> | undefined;
11
16
  }
12
17
 
13
18
  export type OAuth2UserInfo = {
14
19
  id: string | number;
15
- name?: string;
16
- email?: string | null;
17
- image?: string;
20
+ name?: string | undefined;
21
+ email?: (string | null) | undefined;
22
+ image?: string | undefined;
18
23
  emailVerified: boolean;
19
24
  };
20
25
 
@@ -26,17 +31,17 @@ export interface OAuthProvider<
26
31
  createAuthorizationURL: (data: {
27
32
  state: string;
28
33
  codeVerifier: string;
29
- scopes?: string[];
34
+ scopes?: string[] | undefined;
30
35
  redirectURI: string;
31
- display?: string;
32
- loginHint?: string;
36
+ display?: string | undefined;
37
+ loginHint?: string | undefined;
33
38
  }) => Promise<URL> | URL;
34
39
  name: string;
35
40
  validateAuthorizationCode: (data: {
36
41
  code: string;
37
42
  redirectURI: string;
38
- codeVerifier?: string;
39
- deviceId?: string;
43
+ codeVerifier?: string | undefined;
44
+ deviceId?: string | undefined;
40
45
  }) => Promise<OAuth2Tokens>;
41
46
  getUserInfo: (
42
47
  token: OAuth2Tokens & {
@@ -44,13 +49,15 @@ export interface OAuthProvider<
44
49
  * The user object from the provider
45
50
  * This is only available for some providers like Apple
46
51
  */
47
- user?: {
48
- name?: {
49
- firstName?: string;
50
- lastName?: string;
51
- };
52
- email?: string;
53
- };
52
+ user?:
53
+ | {
54
+ name?: {
55
+ firstName?: string;
56
+ lastName?: string;
57
+ };
58
+ email?: string;
59
+ }
60
+ | undefined;
54
61
  },
55
62
  ) => Promise<{
56
63
  user: OAuth2UserInfo;
@@ -59,28 +66,32 @@ export interface OAuthProvider<
59
66
  /**
60
67
  * Custom function to refresh a token
61
68
  */
62
- refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
63
- revokeToken?: (token: string) => Promise<void>;
69
+ refreshAccessToken?:
70
+ | ((refreshToken: string) => Promise<OAuth2Tokens>)
71
+ | undefined;
72
+ revokeToken?: ((token: string) => Promise<void>) | undefined;
64
73
  /**
65
74
  * Verify the id token
66
75
  * @param token - The id token
67
76
  * @param nonce - The nonce
68
77
  * @returns True if the id token is valid, false otherwise
69
78
  */
70
- verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
79
+ verifyIdToken?:
80
+ | ((token: string, nonce?: string) => Promise<boolean>)
81
+ | undefined;
71
82
  /**
72
83
  * Disable implicit sign up for new users. When set to true for the provider,
73
84
  * sign-in need to be called with with requestSignUp as true to create new users.
74
85
  */
75
- disableImplicitSignUp?: boolean;
86
+ disableImplicitSignUp?: boolean | undefined;
76
87
  /**
77
88
  * Disable sign up for new users.
78
89
  */
79
- disableSignUp?: boolean;
90
+ disableSignUp?: boolean | undefined;
80
91
  /**
81
92
  * Options for the provider
82
93
  */
83
- options?: O;
94
+ options?: O | undefined;
84
95
  }
85
96
 
86
97
  export type ProviderOptions<Profile extends Record<string, any> = any> = {
@@ -89,106 +100,117 @@ export type ProviderOptions<Profile extends Record<string, any> = any> = {
89
100
  *
90
101
  * This is usually a string but can be any type depending on the provider.
91
102
  */
92
- clientId?: unknown;
103
+ clientId?: unknown | undefined;
93
104
  /**
94
105
  * The client secret of your application
95
106
  */
96
- clientSecret?: string;
107
+ clientSecret?: string | undefined;
97
108
  /**
98
109
  * The scopes you want to request from the provider
99
110
  */
100
- scope?: string[];
111
+ scope?: string[] | undefined;
101
112
  /**
102
113
  * Remove default scopes of the provider
103
114
  */
104
- disableDefaultScope?: boolean;
115
+ disableDefaultScope?: boolean | undefined;
105
116
  /**
106
117
  * The redirect URL for your application. This is where the provider will
107
118
  * redirect the user after the sign in process. Make sure this URL is
108
119
  * whitelisted in the provider's dashboard.
109
120
  */
110
- redirectURI?: string;
121
+ redirectURI?: string | undefined;
111
122
  /**
112
123
  * The client key of your application
113
124
  * Tiktok Social Provider uses this field instead of clientId
114
125
  */
115
- clientKey?: string;
126
+ clientKey?: string | undefined;
116
127
  /**
117
128
  * Disable provider from allowing users to sign in
118
129
  * with this provider with an id token sent from the
119
130
  * client.
120
131
  */
121
- disableIdTokenSignIn?: boolean;
132
+ disableIdTokenSignIn?: boolean | undefined;
122
133
  /**
123
134
  * verifyIdToken function to verify the id token
124
135
  */
125
- verifyIdToken?: (token: string, nonce?: string) => Promise<boolean>;
136
+ verifyIdToken?:
137
+ | ((token: string, nonce?: string) => Promise<boolean>)
138
+ | undefined;
126
139
  /**
127
140
  * Custom function to get user info from the provider
128
141
  */
129
- getUserInfo?: (token: OAuth2Tokens) => Promise<{
130
- user: {
131
- id: string;
132
- name?: string;
133
- email?: string | null;
134
- image?: string;
135
- emailVerified: boolean;
136
- [key: string]: any;
137
- };
138
- data: any;
139
- }>;
142
+ getUserInfo?:
143
+ | ((token: OAuth2Tokens) => Promise<{
144
+ user: {
145
+ id: string;
146
+ name?: string;
147
+ email?: string | null;
148
+ image?: string;
149
+ emailVerified: boolean;
150
+ [key: string]: any;
151
+ };
152
+ data: any;
153
+ }>)
154
+ | undefined;
140
155
  /**
141
156
  * Custom function to refresh a token
142
157
  */
143
- refreshAccessToken?: (refreshToken: string) => Promise<OAuth2Tokens>;
158
+ refreshAccessToken?:
159
+ | ((refreshToken: string) => Promise<OAuth2Tokens>)
160
+ | undefined;
144
161
  /**
145
162
  * Custom function to map the provider profile to a
146
163
  * user.
147
164
  */
148
- mapProfileToUser?: (profile: Profile) =>
149
- | {
150
- id?: string;
151
- name?: string;
152
- email?: string | null;
153
- image?: string;
154
- emailVerified?: boolean;
155
- [key: string]: any;
156
- }
157
- | Promise<{
158
- id?: string;
159
- name?: string;
160
- email?: string | null;
161
- image?: string;
162
- emailVerified?: boolean;
163
- [key: string]: any;
164
- }>;
165
+ mapProfileToUser?:
166
+ | ((profile: Profile) =>
167
+ | {
168
+ id?: string;
169
+ name?: string;
170
+ email?: string | null;
171
+ image?: string;
172
+ emailVerified?: boolean;
173
+ [key: string]: any;
174
+ }
175
+ | Promise<{
176
+ id?: string;
177
+ name?: string;
178
+ email?: string | null;
179
+ image?: string;
180
+ emailVerified?: boolean;
181
+ [key: string]: any;
182
+ }>)
183
+ | undefined;
165
184
  /**
166
185
  * Disable implicit sign up for new users. When set to true for the provider,
167
186
  * sign-in need to be called with with requestSignUp as true to create new users.
168
187
  */
169
- disableImplicitSignUp?: boolean;
188
+ disableImplicitSignUp?: boolean | undefined;
170
189
  /**
171
190
  * Disable sign up for new users.
172
191
  */
173
- disableSignUp?: boolean;
192
+ disableSignUp?: boolean | undefined;
174
193
  /**
175
194
  * The prompt to use for the authorization code request
176
195
  */
177
196
  prompt?:
178
- | "select_account"
179
- | "consent"
180
- | "login"
181
- | "none"
182
- | "select_account consent";
197
+ | (
198
+ | "select_account"
199
+ | "consent"
200
+ | "login"
201
+ | "none"
202
+ | "select_account consent"
203
+ )
204
+ | undefined;
183
205
  /**
184
206
  * The response mode to use for the authorization code request
185
207
  */
186
- responseMode?: "query" | "form_post";
208
+ responseMode?: ("query" | "form_post") | undefined;
187
209
  /**
188
210
  * If enabled, the user info will be overridden with the provider user info
189
211
  * This is useful if you want to use the provider user info to update the user info
190
212
  *
191
213
  * @default false
192
214
  */
193
- overrideUserInfoOnSignIn?: boolean;
215
+ overrideUserInfoOnSignIn?: boolean | undefined;
194
216
  };
@@ -1,6 +1,6 @@
1
+ import { base64 } from "@better-auth/utils/base64";
1
2
  import { betterFetch } from "@better-fetch/fetch";
2
3
  import type { OAuth2Tokens, ProviderOptions } from "./oauth-provider";
3
- import { base64 } from "@better-auth/utils/base64";
4
4
 
5
5
  export function createRefreshAccessTokenRequest({
6
6
  refreshToken,
@@ -11,9 +11,9 @@ export function createRefreshAccessTokenRequest({
11
11
  }: {
12
12
  refreshToken: string;
13
13
  options: Partial<ProviderOptions>;
14
- authentication?: "basic" | "post";
15
- extraParams?: Record<string, string>;
16
- resource?: string | string[];
14
+ authentication?: ("basic" | "post") | undefined;
15
+ extraParams?: Record<string, string> | undefined;
16
+ resource?: (string | string[]) | undefined;
17
17
  }) {
18
18
  const body = new URLSearchParams();
19
19
  const headers: Record<string, any> = {
@@ -78,10 +78,10 @@ export async function refreshAccessToken({
78
78
  refreshToken: string;
79
79
  options: Partial<ProviderOptions>;
80
80
  tokenEndpoint: string;
81
- authentication?: "basic" | "post";
82
- extraParams?: Record<string, string>;
81
+ authentication?: ("basic" | "post") | undefined;
82
+ extraParams?: Record<string, string> | undefined;
83
83
  /** @deprecated always "refresh_token" */
84
- grantType?: string;
84
+ grantType?: string | undefined;
85
85
  }): Promise<OAuth2Tokens> {
86
86
  const { body, headers } = createRefreshAccessTokenRequest({
87
87
  refreshToken,
@@ -92,11 +92,11 @@ export async function refreshAccessToken({
92
92
 
93
93
  const { data, error } = await betterFetch<{
94
94
  access_token: string;
95
- refresh_token?: string;
96
- expires_in?: number;
97
- token_type?: string;
98
- scope?: string;
99
- id_token?: string;
95
+ refresh_token?: string | undefined;
96
+ expires_in?: number | undefined;
97
+ token_type?: string | undefined;
98
+ scope?: string | undefined;
99
+ id_token?: string | undefined;
100
100
  }>(tokenEndpoint, {
101
101
  method: "POST",
102
102
  body,
@@ -23,6 +23,8 @@ export function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens {
23
23
  : data.scope
24
24
  : [],
25
25
  idToken: data.id_token,
26
+ // Preserve the raw token response for provider-specific fields
27
+ raw: data,
26
28
  };
27
29
  }
28
30
 
@@ -1,8 +1,8 @@
1
+ import { base64 } from "@better-auth/utils/base64";
1
2
  import { betterFetch } from "@better-fetch/fetch";
2
3
  import { jwtVerify } from "jose";
3
4
  import type { ProviderOptions } from "./index";
4
5
  import { getOAuth2Tokens } from "./index";
5
- import { base64 } from "@better-auth/utils/base64";
6
6
 
7
7
  export function createAuthorizationCodeRequest({
8
8
  code,
@@ -18,18 +18,17 @@ export function createAuthorizationCodeRequest({
18
18
  code: string;
19
19
  redirectURI: string;
20
20
  options: Partial<ProviderOptions>;
21
- codeVerifier?: string;
22
- deviceId?: string;
23
- authentication?: "basic" | "post";
24
- headers?: Record<string, string>;
25
- additionalParams?: Record<string, string>;
26
- resource?: string | string[];
21
+ codeVerifier?: string | undefined;
22
+ deviceId?: string | undefined;
23
+ authentication?: ("basic" | "post") | undefined;
24
+ headers?: Record<string, string> | undefined;
25
+ additionalParams?: Record<string, string> | undefined;
26
+ resource?: (string | string[]) | undefined;
27
27
  }) {
28
28
  const body = new URLSearchParams();
29
29
  const requestHeaders: Record<string, any> = {
30
30
  "content-type": "application/x-www-form-urlencoded",
31
31
  accept: "application/json",
32
- "user-agent": "better-auth",
33
32
  ...headers,
34
33
  };
35
34
  body.set("grant_type", "authorization_code");
@@ -92,13 +91,13 @@ export async function validateAuthorizationCode({
92
91
  code: string;
93
92
  redirectURI: string;
94
93
  options: Partial<ProviderOptions>;
95
- codeVerifier?: string;
96
- deviceId?: string;
94
+ codeVerifier?: string | undefined;
95
+ deviceId?: string | undefined;
97
96
  tokenEndpoint: string;
98
- authentication?: "basic" | "post";
99
- headers?: Record<string, string>;
100
- additionalParams?: Record<string, string>;
101
- resource?: string | string[];
97
+ authentication?: ("basic" | "post") | undefined;
98
+ headers?: Record<string, string> | undefined;
99
+ additionalParams?: Record<string, string> | undefined;
100
+ resource?: (string | string[]) | undefined;
102
101
  }) {
103
102
  const { body, headers: requestHeaders } = createAuthorizationCodeRequest({
104
103
  code,
@@ -139,7 +138,6 @@ export async function validateToken(token: string, jwksEndpoint: string) {
139
138
  method: "GET",
140
139
  headers: {
141
140
  accept: "application/json",
142
- "user-agent": "better-auth",
143
141
  },
144
142
  });
145
143
  if (error) {
@@ -1,12 +1,12 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
2
  import { APIError } from "better-call";
3
3
  import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
4
- import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
4
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
5
  import {
6
- refreshAccessToken,
7
6
  createAuthorizationURL,
7
+ refreshAccessToken,
8
8
  validateAuthorizationCode,
9
- } from "@better-auth/core/oauth2";
9
+ } from "../oauth2";
10
10
  export interface AppleProfile {
11
11
  /**
12
12
  * The subject registered claim identifies the principal that’s the subject
@@ -52,7 +52,7 @@ export interface AppleProfile {
52
52
  * The URL to the user's profile picture.
53
53
  */
54
54
  picture: string;
55
- user?: AppleNonConformUser;
55
+ user?: AppleNonConformUser | undefined;
56
56
  }
57
57
 
58
58
  /**
@@ -70,8 +70,8 @@ export interface AppleNonConformUser {
70
70
 
71
71
  export interface AppleOptions extends ProviderOptions<AppleProfile> {
72
72
  clientId: string;
73
- appBundleIdentifier?: string;
74
- audience?: string | string[];
73
+ appBundleIdentifier?: string | undefined;
74
+ audience?: (string | string[]) | undefined;
75
75
  }
76
76
 
77
77
  export const apple = (options: AppleOptions) => {
@@ -81,8 +81,8 @@ export const apple = (options: AppleOptions) => {
81
81
  name: "Apple",
82
82
  async createAuthorizationURL({ state, scopes, redirectURI }) {
83
83
  const _scope = options.disableDefaultScope ? [] : ["email", "name"];
84
- options.scope && _scope.push(...options.scope);
85
- scopes && _scope.push(...scopes);
84
+ if (options.scope) _scope.push(...options.scope);
85
+ if (scopes) _scope.push(...scopes);
86
86
  const url = await createAuthorizationURL({
87
87
  id: "apple",
88
88
  options,
@@ -1,27 +1,29 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
+ import { logger } from "../env";
2
3
  import { BetterAuthError } from "../error";
3
- import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
4
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
4
5
  import {
5
6
  createAuthorizationURL,
7
+ refreshAccessToken,
6
8
  validateAuthorizationCode,
7
- } from "@better-auth/core/oauth2";
8
- import { logger } from "@better-auth/core/env";
9
- import { refreshAccessToken } from "@better-auth/core/oauth2";
9
+ } from "../oauth2";
10
10
 
11
11
  export interface AtlassianProfile {
12
- account_type?: string;
12
+ account_type?: string | undefined;
13
13
  account_id: string;
14
- email?: string;
14
+ email?: string | undefined;
15
15
  name: string;
16
- picture?: string;
17
- nickname?: string;
18
- locale?: string;
19
- extended_profile?: {
20
- job_title?: string;
21
- organization?: string;
22
- department?: string;
23
- location?: string;
24
- };
16
+ picture?: string | undefined;
17
+ nickname?: string | undefined;
18
+ locale?: string | undefined;
19
+ extended_profile?:
20
+ | {
21
+ job_title?: string;
22
+ organization?: string;
23
+ department?: string;
24
+ location?: string;
25
+ }
26
+ | undefined;
25
27
  }
26
28
  export interface AtlassianOptions extends ProviderOptions<AtlassianProfile> {
27
29
  clientId: string;
@@ -44,8 +46,8 @@ export const atlassian = (options: AtlassianOptions) => {
44
46
  const _scopes = options.disableDefaultScope
45
47
  ? []
46
48
  : ["read:jira-user", "offline_access"];
47
- options.scope && _scopes.push(...options.scope);
48
- scopes && _scopes.push(...scopes);
49
+ if (options.scope) _scopes.push(...options.scope);
50
+ if (scopes) _scopes.push(...scopes);
49
51
 
50
52
  return createAuthorizationURL({
51
53
  id: "atlassian",
@@ -98,8 +100,8 @@ export const atlassian = (options: AtlassianOptions) => {
98
100
  const { data: profile } = await betterFetch<{
99
101
  account_id: string;
100
102
  name: string;
101
- email?: string;
102
- picture?: string;
103
+ email?: string | undefined;
104
+ picture?: string | undefined;
103
105
  }>("https://api.atlassian.com/me", {
104
106
  headers: { Authorization: `Bearer ${token.accessToken}` },
105
107
  });
@@ -1,27 +1,27 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
+ import { APIError } from "better-call";
2
3
  import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
4
+ import { logger } from "../env";
3
5
  import { BetterAuthError } from "../error";
4
- import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
6
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
7
  import {
6
8
  createAuthorizationURL,
9
+ refreshAccessToken,
7
10
  validateAuthorizationCode,
8
- } from "@better-auth/core/oauth2";
9
- import { logger } from "@better-auth/core/env";
10
- import { refreshAccessToken } from "@better-auth/core/oauth2";
11
- import { APIError } from "better-call";
11
+ } from "../oauth2";
12
12
 
13
13
  export interface CognitoProfile {
14
14
  sub: string;
15
15
  email: string;
16
16
  email_verified: boolean;
17
17
  name: string;
18
- given_name?: string;
19
- family_name?: string;
20
- picture?: string;
21
- username?: string;
22
- locale?: string;
23
- phone_number?: string;
24
- phone_number_verified?: boolean;
18
+ given_name?: string | undefined;
19
+ family_name?: string | undefined;
20
+ picture?: string | undefined;
21
+ username?: string | undefined;
22
+ locale?: string | undefined;
23
+ phone_number?: string | undefined;
24
+ phone_number_verified?: boolean | undefined;
25
25
  aud: string;
26
26
  iss: string;
27
27
  exp: number;
@@ -41,7 +41,7 @@ export interface CognitoOptions extends ProviderOptions<CognitoProfile> {
41
41
  */
42
42
  region: string;
43
43
  userPoolId: string;
44
- requireClientSecret?: boolean;
44
+ requireClientSecret?: boolean | undefined;
45
45
  }
46
46
 
47
47
  export const cognito = (options: CognitoOptions) => {
@@ -77,8 +77,8 @@ export const cognito = (options: CognitoOptions) => {
77
77
  const _scopes = options.disableDefaultScope
78
78
  ? []
79
79
  : ["openid", "profile", "email"];
80
- options.scope && _scopes.push(...options.scope);
81
- scopes && _scopes.push(...scopes);
80
+ if (options.scope) _scopes.push(...options.scope);
81
+ if (scopes) _scopes.push(...scopes);
82
82
 
83
83
  const url = await createAuthorizationURL({
84
84
  id: "cognito",
@@ -1,9 +1,6 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
3
- import {
4
- refreshAccessToken,
5
- validateAuthorizationCode,
6
- } from "@better-auth/core/oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
+ import { refreshAccessToken, validateAuthorizationCode } from "../oauth2";
7
4
  export interface DiscordProfile extends Record<string, any> {
8
5
  /** the user's id (i.e. the numerical snowflake) */
9
6
  id: string;
@@ -19,12 +16,12 @@ export interface DiscordProfile extends Record<string, any> {
19
16
  */
20
17
  avatar: string | null;
21
18
  /** whether the user belongs to an OAuth2 application */
22
- bot?: boolean;
19
+ bot?: boolean | undefined;
23
20
  /**
24
21
  * whether the user is an Official Discord System user (part of the urgent
25
22
  * message system)
26
23
  */
27
- system?: boolean;
24
+ system?: boolean | undefined;
28
25
  /** whether the user has two factor enabled on their account */
29
26
  mfa_enabled: boolean;
30
27
  /**
@@ -78,8 +75,8 @@ export interface DiscordProfile extends Record<string, any> {
78
75
 
79
76
  export interface DiscordOptions extends ProviderOptions<DiscordProfile> {
80
77
  clientId: string;
81
- prompt?: "none" | "consent";
82
- permissions?: number;
78
+ prompt?: ("none" | "consent") | undefined;
79
+ permissions?: number | undefined;
83
80
  }
84
81
 
85
82
  export const discord = (options: DiscordOptions) => {
@@ -88,8 +85,8 @@ export const discord = (options: DiscordOptions) => {
88
85
  name: "Discord",
89
86
  createAuthorizationURL({ state, scopes, redirectURI }) {
90
87
  const _scopes = options.disableDefaultScope ? [] : ["identify", "email"];
91
- scopes && _scopes.push(...scopes);
92
- options.scope && _scopes.push(...options.scope);
88
+ if (scopes) _scopes.push(...scopes);
89
+ if (options.scope) _scopes.push(...options.scope);
93
90
  const hasBotScope = _scopes.includes("bot");
94
91
  const permissionsParam =
95
92
  hasBotScope && options.permissions !== undefined
@@ -1,10 +1,10 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { OAuthProvider, ProviderOptions } from "@better-auth/core/oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
6
  validateAuthorizationCode,
7
- } from "@better-auth/core/oauth2";
7
+ } from "../oauth2";
8
8
 
9
9
  export interface DropboxProfile {
10
10
  account_id: string;
@@ -22,7 +22,7 @@ export interface DropboxProfile {
22
22
 
23
23
  export interface DropboxOptions extends ProviderOptions<DropboxProfile> {
24
24
  clientId: string;
25
- accessType?: "offline" | "online" | "legacy";
25
+ accessType?: ("offline" | "online" | "legacy") | undefined;
26
26
  }
27
27
 
28
28
  export const dropbox = (options: DropboxOptions) => {
@@ -38,8 +38,8 @@ export const dropbox = (options: DropboxOptions) => {
38
38
  redirectURI,
39
39
  }) => {
40
40
  const _scopes = options.disableDefaultScope ? [] : ["account_info.read"];
41
- options.scope && _scopes.push(...options.scope);
42
- scopes && _scopes.push(...scopes);
41
+ if (options.scope) _scopes.push(...options.scope);
42
+ if (scopes) _scopes.push(...scopes);
43
43
  const additionalParams: Record<string, string> = {};
44
44
  if (options.accessType) {
45
45
  additionalParams.token_access_type = options.accessType;