@better-auth/core 1.4.0-beta.8 → 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.
- package/.turbo/turbo-build.log +41 -34
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +26 -0
- package/dist/async_hooks/index.d.mts +2 -10
- package/dist/async_hooks/index.mjs +2 -24
- package/dist/async_hooks-BfRfbd1J.mjs +18 -0
- package/dist/context/index.d.mts +54 -0
- package/dist/context/index.mjs +4 -0
- package/dist/context-DgQ9XGBl.mjs +114 -0
- package/dist/db/adapter/index.d.mts +3 -23
- package/dist/db/adapter/index.mjs +1 -1
- package/dist/db/index.d.mts +3 -127
- package/dist/db/index.mjs +46 -55
- package/dist/env/index.d.mts +2 -85
- package/dist/env/index.mjs +2 -299
- package/dist/env-DwlNAN_D.mjs +245 -0
- package/dist/error/index.d.mts +35 -0
- package/dist/error/index.mjs +4 -0
- package/dist/error-BhAKg8LX.mjs +45 -0
- package/dist/index-CdubV7uy.d.mts +82 -0
- package/dist/index-CkAWdKH8.d.mts +7352 -0
- package/dist/index-DgwIISs7.d.mts +7 -0
- package/dist/index.d.mts +3 -115
- package/dist/index.mjs +1 -1
- package/dist/oauth2/index.d.mts +3 -277
- package/dist/oauth2/index.mjs +2 -356
- package/dist/oauth2-DmgZmPEg.mjs +236 -0
- package/dist/social-providers/index.d.mts +3 -0
- package/dist/social-providers/index.mjs +2523 -0
- package/dist/utils/index.d.mts +9 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils-C5EN75oV.mjs +7 -0
- package/package.json +90 -62
- package/src/api/index.ts +53 -0
- package/src/async_hooks/index.ts +1 -9
- package/src/context/endpoint-context.ts +49 -0
- package/src/context/index.ts +21 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +90 -0
- package/src/context/transaction.ts +73 -0
- package/src/db/adapter/index.ts +518 -8
- package/src/db/index.ts +12 -11
- package/src/db/plugin.ts +3 -3
- package/src/db/type.ts +55 -52
- package/src/env/color-depth.ts +5 -4
- package/src/env/env-impl.ts +2 -1
- package/src/env/index.ts +9 -9
- package/src/env/logger.test.ts +3 -2
- package/src/env/logger.ts +11 -9
- package/src/error/codes.ts +31 -0
- package/src/error/index.ts +11 -0
- package/src/index.ts +0 -2
- package/src/oauth2/client-credentials-token.ts +9 -9
- package/src/oauth2/create-authorization-url.ts +12 -12
- package/src/oauth2/index.ts +10 -11
- package/src/oauth2/oauth-provider.ts +96 -74
- package/src/oauth2/refresh-access-token.ts +12 -12
- package/src/oauth2/utils.ts +2 -0
- package/src/oauth2/validate-authorization-code.ts +13 -15
- package/src/social-providers/apple.ts +213 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +269 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +206 -0
- package/src/social-providers/figma.ts +115 -0
- package/src/social-providers/github.ts +154 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +171 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +124 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +93 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +259 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +111 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +210 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vk.ts +125 -0
- package/src/social-providers/zoom.ts +233 -0
- package/src/types/context.ts +270 -0
- package/src/types/cookie.ts +8 -0
- package/src/types/index.ts +21 -1
- package/src/types/init-options.ts +1328 -68
- package/src/types/plugin-client.ts +117 -0
- package/src/types/plugin.ts +158 -0
- package/src/utils/error-codes.ts +51 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.json +2 -5
- package/tsdown.config.ts +20 -0
- package/vitest.config.ts +3 -0
- package/build.config.ts +0 -19
- package/dist/async_hooks/index.cjs +0 -27
- package/dist/async_hooks/index.d.cts +0 -10
- package/dist/async_hooks/index.d.ts +0 -10
- package/dist/db/adapter/index.cjs +0 -2
- package/dist/db/adapter/index.d.cts +0 -23
- package/dist/db/adapter/index.d.ts +0 -23
- package/dist/db/index.cjs +0 -91
- package/dist/db/index.d.cts +0 -127
- package/dist/db/index.d.ts +0 -127
- package/dist/env/index.cjs +0 -315
- package/dist/env/index.d.cts +0 -85
- package/dist/env/index.d.ts +0 -85
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +0 -115
- package/dist/index.d.ts +0 -115
- package/dist/oauth2/index.cjs +0 -368
- package/dist/oauth2/index.d.cts +0 -277
- package/dist/oauth2/index.d.ts +0 -277
- package/dist/shared/core.DeNN5HMO.d.cts +0 -143
- package/dist/shared/core.DeNN5HMO.d.mts +0 -143
- package/dist/shared/core.DeNN5HMO.d.ts +0 -143
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
generateCodeChallenge,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export type LoginType =
|
|
10
|
+
| 0 /** Facebook OAuth */
|
|
11
|
+
| 1 /** Google OAuth */
|
|
12
|
+
| 24 /** Apple OAuth */
|
|
13
|
+
| 27 /** Microsoft OAuth */
|
|
14
|
+
| 97 /** Mobile device */
|
|
15
|
+
| 98 /** RingCentral OAuth */
|
|
16
|
+
| 99 /** API user */
|
|
17
|
+
| 100 /** Zoom Work email */
|
|
18
|
+
| 101; /** Single Sign-On (SSO) */
|
|
19
|
+
|
|
20
|
+
export type AccountStatus = "pending" | "active" | "inactive";
|
|
21
|
+
|
|
22
|
+
export type PronounOption =
|
|
23
|
+
| 1 /** Ask the user every time */
|
|
24
|
+
| 2 /** Always display */
|
|
25
|
+
| 3; /** Do not display */
|
|
26
|
+
|
|
27
|
+
export interface PhoneNumber {
|
|
28
|
+
/** The country code of the phone number (Example: "+1") */
|
|
29
|
+
code: string;
|
|
30
|
+
|
|
31
|
+
/** The country of the phone number (Example: "US") */
|
|
32
|
+
country: string;
|
|
33
|
+
|
|
34
|
+
/** The label for the phone number (Example: "Mobile") */
|
|
35
|
+
label: string;
|
|
36
|
+
|
|
37
|
+
/** The phone number itself (Example: "800000000") */
|
|
38
|
+
number: string;
|
|
39
|
+
|
|
40
|
+
/** Whether the phone number has been verified (Example: true) */
|
|
41
|
+
verified: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* See the full documentation below:
|
|
46
|
+
* https://developers.zoom.us/docs/api/users/#tag/users/GET/users/{userId}
|
|
47
|
+
*/
|
|
48
|
+
export interface ZoomProfile extends Record<string, any> {
|
|
49
|
+
/** The user's account ID (Example: "q6gBJVO5TzexKYTb_I2rpg") */
|
|
50
|
+
account_id: string;
|
|
51
|
+
/** The user's account number (Example: 10009239) */
|
|
52
|
+
account_number: number;
|
|
53
|
+
/** The user's cluster (Example: "us04") */
|
|
54
|
+
cluster: string;
|
|
55
|
+
/** The user's CMS ID. Only enabled for Kaltura integration (Example: "KDcuGIm1QgePTO8WbOqwIQ") */
|
|
56
|
+
cms_user_id: string;
|
|
57
|
+
/** The user's cost center (Example: "cost center") */
|
|
58
|
+
cost_center: string;
|
|
59
|
+
/** User create time (Example: "2018-10-31T04:32:37Z") */
|
|
60
|
+
created_at: string;
|
|
61
|
+
/** Department (Example: "Developers") */
|
|
62
|
+
dept: string;
|
|
63
|
+
/** User's display name (Example: "Jill Chill") */
|
|
64
|
+
display_name: string;
|
|
65
|
+
/** User's email address (Example: "jchill@example.com") */
|
|
66
|
+
email: string;
|
|
67
|
+
/** User's first name (Example: "Jill") */
|
|
68
|
+
first_name: string;
|
|
69
|
+
/** IDs of the web groups that the user belongs to (Example: ["RSMaSp8sTEGK0_oamiA2_w"]) */
|
|
70
|
+
group_ids: string[];
|
|
71
|
+
/** User ID (Example: "zJKyaiAyTNC-MWjiWC18KQ") */
|
|
72
|
+
id: string;
|
|
73
|
+
/** IM IDs of the groups that the user belongs to (Example: ["t-_-d56CSWG-7BF15LLrOw"]) */
|
|
74
|
+
im_group_ids: string[];
|
|
75
|
+
/** The user's JID (Example: "jchill@example.com") */
|
|
76
|
+
jid: string;
|
|
77
|
+
/** The user's job title (Example: "API Developer") */
|
|
78
|
+
job_title: string;
|
|
79
|
+
/** Default language for the Zoom Web Portal (Example: "en-US") */
|
|
80
|
+
language: string;
|
|
81
|
+
/** User last login client version (Example: "5.9.6.4993(mac)") */
|
|
82
|
+
last_client_version: string;
|
|
83
|
+
/** User last login time (Example: "2021-05-05T20:40:30Z") */
|
|
84
|
+
last_login_time: string;
|
|
85
|
+
/** User's last name (Example: "Chill") */
|
|
86
|
+
last_name: string;
|
|
87
|
+
/** The time zone of the user (Example: "Asia/Shanghai") */
|
|
88
|
+
timezone: string;
|
|
89
|
+
/** User's location (Example: "Paris") */
|
|
90
|
+
location: string;
|
|
91
|
+
/** The user's login method (Example: 101) */
|
|
92
|
+
login_types: LoginType[];
|
|
93
|
+
/** User's personal meeting URL (Example: "example.com") */
|
|
94
|
+
personal_meeting_url: string;
|
|
95
|
+
/** This field has been deprecated and will not be supported in the future.
|
|
96
|
+
* Use the phone_numbers field instead of this field.
|
|
97
|
+
* The user's phone number (Example: "+1 800000000") */
|
|
98
|
+
// @deprecated true
|
|
99
|
+
phone_number?: string | undefined;
|
|
100
|
+
/** The URL for user's profile picture (Example: "example.com") */
|
|
101
|
+
pic_url: string;
|
|
102
|
+
/** Personal Meeting ID (PMI) (Example: 3542471135) */
|
|
103
|
+
pmi: number;
|
|
104
|
+
/** Unique identifier of the user's assigned role (Example: "0") */
|
|
105
|
+
role_id: string;
|
|
106
|
+
/** User's role name (Example: "Admin") */
|
|
107
|
+
role_name: string;
|
|
108
|
+
/** Status of user's account (Example: "pending") */
|
|
109
|
+
status: AccountStatus;
|
|
110
|
+
/** Use the personal meeting ID (PMI) for instant meetings (Example: false) */
|
|
111
|
+
use_pmi: boolean;
|
|
112
|
+
/** The time and date when the user was created (Example: "2018-10-31T04:32:37Z") */
|
|
113
|
+
user_created_at: string;
|
|
114
|
+
/** Displays whether user is verified or not (Example: 1) */
|
|
115
|
+
verified: number;
|
|
116
|
+
/** The user's Zoom Workplace plan option (Example: 64) */
|
|
117
|
+
zoom_one_type: number;
|
|
118
|
+
/** The user's company (Example: "Jill") */
|
|
119
|
+
company?: string | undefined;
|
|
120
|
+
/** Custom attributes that have been assigned to the user (Example: [{ "key": "cbf_cywdkexrtqc73f97gd4w6g", "name": "A1", "value": "1" }]) */
|
|
121
|
+
custom_attributes?:
|
|
122
|
+
| { key: string; name: string; value: string }[]
|
|
123
|
+
| undefined;
|
|
124
|
+
/** The employee's unique ID. This field only returns when SAML single sign-on (SSO) is enabled.
|
|
125
|
+
* The `login_type` value is `101` (SSO) (Example: "HqDyI037Qjili1kNsSIrIg") */
|
|
126
|
+
employee_unique_id?: string | undefined;
|
|
127
|
+
/** The manager for the user (Example: "thill@example.com") */
|
|
128
|
+
manager?: string | undefined;
|
|
129
|
+
/** The user's country for the company phone number (Example: "US")
|
|
130
|
+
* @deprecated true */
|
|
131
|
+
phone_country?: string | undefined;
|
|
132
|
+
/** The phone number's ISO country code (Example: "+1") */
|
|
133
|
+
phone_numbers?: PhoneNumber[] | undefined;
|
|
134
|
+
/** The user's plan type (Example: "1") */
|
|
135
|
+
plan_united_type?: string | undefined;
|
|
136
|
+
/** The user's pronouns (Example: "3123") */
|
|
137
|
+
pronouns?: string | undefined;
|
|
138
|
+
/** The user's display pronouns setting (Example: 1) */
|
|
139
|
+
pronouns_option?: PronounOption | undefined;
|
|
140
|
+
/** Personal meeting room URL, if the user has one (Example: "example.com") */
|
|
141
|
+
vanity_url?: string | undefined;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ZoomOptions extends ProviderOptions<ZoomProfile> {
|
|
145
|
+
clientId: string;
|
|
146
|
+
pkce?: boolean | undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const zoom = (userOptions: ZoomOptions) => {
|
|
150
|
+
const options = {
|
|
151
|
+
pkce: true,
|
|
152
|
+
...userOptions,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
id: "zoom",
|
|
157
|
+
name: "Zoom",
|
|
158
|
+
createAuthorizationURL: async ({ state, redirectURI, codeVerifier }) => {
|
|
159
|
+
const params = new URLSearchParams({
|
|
160
|
+
response_type: "code",
|
|
161
|
+
redirect_uri: options.redirectURI ? options.redirectURI : redirectURI,
|
|
162
|
+
client_id: options.clientId,
|
|
163
|
+
state,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (options.pkce) {
|
|
167
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
168
|
+
params.set("code_challenge_method", "S256");
|
|
169
|
+
params.set("code_challenge", codeChallenge);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const url = new URL("https://zoom.us/oauth/authorize");
|
|
173
|
+
url.search = params.toString();
|
|
174
|
+
|
|
175
|
+
return url;
|
|
176
|
+
},
|
|
177
|
+
validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
|
|
178
|
+
return validateAuthorizationCode({
|
|
179
|
+
code,
|
|
180
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
181
|
+
codeVerifier,
|
|
182
|
+
options,
|
|
183
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
184
|
+
authentication: "post",
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
refreshAccessToken: options.refreshAccessToken
|
|
188
|
+
? options.refreshAccessToken
|
|
189
|
+
: async (refreshToken) =>
|
|
190
|
+
refreshAccessToken({
|
|
191
|
+
refreshToken,
|
|
192
|
+
options: {
|
|
193
|
+
clientId: options.clientId,
|
|
194
|
+
clientKey: options.clientKey,
|
|
195
|
+
clientSecret: options.clientSecret,
|
|
196
|
+
},
|
|
197
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
198
|
+
}),
|
|
199
|
+
async getUserInfo(token) {
|
|
200
|
+
if (options.getUserInfo) {
|
|
201
|
+
return options.getUserInfo(token);
|
|
202
|
+
}
|
|
203
|
+
const { data: profile, error } = await betterFetch<ZoomProfile>(
|
|
204
|
+
"https://api.zoom.us/v2/users/me",
|
|
205
|
+
{
|
|
206
|
+
headers: {
|
|
207
|
+
authorization: `Bearer ${token.accessToken}`,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
if (error) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
user: {
|
|
220
|
+
id: profile.id,
|
|
221
|
+
name: profile.display_name,
|
|
222
|
+
image: profile.pic_url,
|
|
223
|
+
email: profile.email,
|
|
224
|
+
emailVerified: Boolean(profile.verified),
|
|
225
|
+
...userMap,
|
|
226
|
+
},
|
|
227
|
+
data: {
|
|
228
|
+
...profile,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
} satisfies OAuthProvider<ZoomProfile>;
|
|
233
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import type { CookieOptions, EndpointContext } from "better-call";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
BetterAuthDBSchema,
|
|
5
|
+
DBPreservedModels,
|
|
6
|
+
SecondaryStorage,
|
|
7
|
+
Session,
|
|
8
|
+
User,
|
|
9
|
+
Verification,
|
|
10
|
+
} from "../db";
|
|
11
|
+
import type { DBAdapter, Where } from "../db/adapter";
|
|
12
|
+
import type { createLogger } from "../env";
|
|
13
|
+
import type { OAuthProvider } from "../oauth2";
|
|
14
|
+
import type { BetterAuthCookies } from "./cookie";
|
|
15
|
+
import type { LiteralUnion } from "./helper";
|
|
16
|
+
import type {
|
|
17
|
+
BetterAuthOptions,
|
|
18
|
+
BetterAuthRateLimitOptions,
|
|
19
|
+
} from "./init-options";
|
|
20
|
+
|
|
21
|
+
export type GenericEndpointContext<
|
|
22
|
+
Options extends BetterAuthOptions = BetterAuthOptions,
|
|
23
|
+
> = EndpointContext<string, any> & {
|
|
24
|
+
context: AuthContext<Options>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface InternalAdapter<
|
|
28
|
+
Options extends BetterAuthOptions = BetterAuthOptions,
|
|
29
|
+
> {
|
|
30
|
+
createOAuthUser(
|
|
31
|
+
user: Omit<User, "id" | "createdAt" | "updatedAt">,
|
|
32
|
+
account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> &
|
|
33
|
+
Partial<Account>,
|
|
34
|
+
): Promise<{ user: User; account: Account }>;
|
|
35
|
+
|
|
36
|
+
createUser<T extends Record<string, any>>(
|
|
37
|
+
user: Omit<User, "id" | "createdAt" | "updatedAt" | "emailVerified"> &
|
|
38
|
+
Partial<User> &
|
|
39
|
+
Record<string, any>,
|
|
40
|
+
): Promise<T & User>;
|
|
41
|
+
|
|
42
|
+
createAccount<T extends Record<string, any>>(
|
|
43
|
+
account: Omit<Account, "id" | "createdAt" | "updatedAt"> &
|
|
44
|
+
Partial<Account> &
|
|
45
|
+
T,
|
|
46
|
+
): Promise<T & Account>;
|
|
47
|
+
|
|
48
|
+
listSessions(userId: string): Promise<Session[]>;
|
|
49
|
+
|
|
50
|
+
listUsers(
|
|
51
|
+
limit?: number | undefined,
|
|
52
|
+
offset?: number | undefined,
|
|
53
|
+
sortBy?: { field: string; direction: "asc" | "desc" } | undefined,
|
|
54
|
+
where?: Where[] | undefined,
|
|
55
|
+
): Promise<User[]>;
|
|
56
|
+
|
|
57
|
+
countTotalUsers(where?: Where[] | undefined): Promise<number>;
|
|
58
|
+
|
|
59
|
+
deleteUser(userId: string): Promise<void>;
|
|
60
|
+
|
|
61
|
+
createSession(
|
|
62
|
+
userId: string,
|
|
63
|
+
dontRememberMe?: boolean | undefined,
|
|
64
|
+
override?: (Partial<Session> & Record<string, any>) | undefined,
|
|
65
|
+
overrideAll?: boolean | undefined,
|
|
66
|
+
): Promise<Session>;
|
|
67
|
+
|
|
68
|
+
findSession(token: string): Promise<{
|
|
69
|
+
session: Session & Record<string, any>;
|
|
70
|
+
user: User & Record<string, any>;
|
|
71
|
+
} | null>;
|
|
72
|
+
|
|
73
|
+
findSessions(
|
|
74
|
+
sessionTokens: string[],
|
|
75
|
+
): Promise<{ session: Session; user: User }[]>;
|
|
76
|
+
|
|
77
|
+
updateSession(
|
|
78
|
+
sessionToken: string,
|
|
79
|
+
session: Partial<Session> & Record<string, any>,
|
|
80
|
+
): Promise<Session | null>;
|
|
81
|
+
|
|
82
|
+
deleteSession(token: string): Promise<void>;
|
|
83
|
+
|
|
84
|
+
deleteAccounts(userId: string): Promise<void>;
|
|
85
|
+
|
|
86
|
+
deleteAccount(accountId: string): Promise<void>;
|
|
87
|
+
|
|
88
|
+
deleteSessions(userIdOrSessionTokens: string | string[]): Promise<void>;
|
|
89
|
+
|
|
90
|
+
findOAuthUser(
|
|
91
|
+
email: string,
|
|
92
|
+
accountId: string,
|
|
93
|
+
providerId: string,
|
|
94
|
+
): Promise<{ user: User; accounts: Account[] } | null>;
|
|
95
|
+
|
|
96
|
+
findUserByEmail(
|
|
97
|
+
email: string,
|
|
98
|
+
options?: { includeAccounts: boolean } | undefined,
|
|
99
|
+
): Promise<{ user: User; accounts: Account[] } | null>;
|
|
100
|
+
|
|
101
|
+
findUserById(userId: string): Promise<User | null>;
|
|
102
|
+
|
|
103
|
+
linkAccount(
|
|
104
|
+
account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account>,
|
|
105
|
+
): Promise<Account>;
|
|
106
|
+
|
|
107
|
+
// Record<string, any> is to take into account additional fields or plugin-added fields
|
|
108
|
+
updateUser<T extends Record<string, any>>(
|
|
109
|
+
userId: string,
|
|
110
|
+
data: Partial<User> & Record<string, any>,
|
|
111
|
+
): Promise<User & T>;
|
|
112
|
+
|
|
113
|
+
updateUserByEmail<T extends Record<string, any>>(
|
|
114
|
+
email: string,
|
|
115
|
+
data: Partial<User & Record<string, any>>,
|
|
116
|
+
): Promise<User & T>;
|
|
117
|
+
|
|
118
|
+
updatePassword(userId: string, password: string): Promise<void>;
|
|
119
|
+
|
|
120
|
+
findAccounts(userId: string): Promise<Account[]>;
|
|
121
|
+
|
|
122
|
+
findAccount(accountId: string): Promise<Account | null>;
|
|
123
|
+
|
|
124
|
+
findAccountByProviderId(
|
|
125
|
+
accountId: string,
|
|
126
|
+
providerId: string,
|
|
127
|
+
): Promise<Account | null>;
|
|
128
|
+
|
|
129
|
+
findAccountByUserId(userId: string): Promise<Account[]>;
|
|
130
|
+
|
|
131
|
+
updateAccount(id: string, data: Partial<Account>): Promise<Account>;
|
|
132
|
+
|
|
133
|
+
createVerificationValue(
|
|
134
|
+
data: Omit<Verification, "createdAt" | "id" | "updatedAt"> &
|
|
135
|
+
Partial<Verification>,
|
|
136
|
+
): Promise<Verification>;
|
|
137
|
+
|
|
138
|
+
findVerificationValue(identifier: string): Promise<Verification | null>;
|
|
139
|
+
|
|
140
|
+
deleteVerificationValue(id: string): Promise<void>;
|
|
141
|
+
|
|
142
|
+
deleteVerificationByIdentifier(identifier: string): Promise<void>;
|
|
143
|
+
|
|
144
|
+
updateVerificationValue(
|
|
145
|
+
id: string,
|
|
146
|
+
data: Partial<Verification>,
|
|
147
|
+
): Promise<Verification>;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type CreateCookieGetterFn = (
|
|
151
|
+
cookieName: string,
|
|
152
|
+
overrideAttributes?: Partial<CookieOptions> | undefined,
|
|
153
|
+
) => {
|
|
154
|
+
name: string;
|
|
155
|
+
attributes: CookieOptions;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type CheckPasswordFn<Options extends BetterAuthOptions = BetterAuthOptions> = (
|
|
159
|
+
userId: string,
|
|
160
|
+
ctx: GenericEndpointContext<Options>,
|
|
161
|
+
) => Promise<boolean>;
|
|
162
|
+
|
|
163
|
+
export type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> =
|
|
164
|
+
{
|
|
165
|
+
options: Options;
|
|
166
|
+
appName: string;
|
|
167
|
+
baseURL: string;
|
|
168
|
+
trustedOrigins: string[];
|
|
169
|
+
oauthConfig: {
|
|
170
|
+
/**
|
|
171
|
+
* This is dangerous and should only be used in dev or staging environments.
|
|
172
|
+
*/
|
|
173
|
+
skipStateCookieCheck?: boolean | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Strategy for storing OAuth state
|
|
176
|
+
*
|
|
177
|
+
* - "cookie": Store state in an encrypted cookie (stateless)
|
|
178
|
+
* - "database": Store state in the database
|
|
179
|
+
*
|
|
180
|
+
* @default "cookie"
|
|
181
|
+
*/
|
|
182
|
+
storeStateStrategy: "database" | "cookie";
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* New session that will be set after the request
|
|
186
|
+
* meaning: there is a `set-cookie` header that will set
|
|
187
|
+
* the session cookie. This is the fetched session. And it's set
|
|
188
|
+
* by `setNewSession` method.
|
|
189
|
+
*/
|
|
190
|
+
newSession: {
|
|
191
|
+
session: Session & Record<string, any>;
|
|
192
|
+
user: User & Record<string, any>;
|
|
193
|
+
} | null;
|
|
194
|
+
session: {
|
|
195
|
+
session: Session & Record<string, any>;
|
|
196
|
+
user: User & Record<string, any>;
|
|
197
|
+
} | null;
|
|
198
|
+
setNewSession: (
|
|
199
|
+
session: {
|
|
200
|
+
session: Session & Record<string, any>;
|
|
201
|
+
user: User & Record<string, any>;
|
|
202
|
+
} | null,
|
|
203
|
+
) => void;
|
|
204
|
+
socialProviders: OAuthProvider[];
|
|
205
|
+
authCookies: BetterAuthCookies;
|
|
206
|
+
logger: ReturnType<typeof createLogger>;
|
|
207
|
+
rateLimit: {
|
|
208
|
+
enabled: boolean;
|
|
209
|
+
window: number;
|
|
210
|
+
max: number;
|
|
211
|
+
storage: "memory" | "database" | "secondary-storage";
|
|
212
|
+
} & BetterAuthRateLimitOptions;
|
|
213
|
+
adapter: DBAdapter<Options>;
|
|
214
|
+
internalAdapter: InternalAdapter<Options>;
|
|
215
|
+
createAuthCookie: CreateCookieGetterFn;
|
|
216
|
+
secret: string;
|
|
217
|
+
sessionConfig: {
|
|
218
|
+
updateAge: number;
|
|
219
|
+
expiresIn: number;
|
|
220
|
+
freshAge: number;
|
|
221
|
+
cookieRefreshCache:
|
|
222
|
+
| false
|
|
223
|
+
| {
|
|
224
|
+
enabled: true;
|
|
225
|
+
updateAge: number;
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
generateId: (options: {
|
|
229
|
+
model: LiteralUnion<DBPreservedModels, string>;
|
|
230
|
+
size?: number | undefined;
|
|
231
|
+
}) => string | false;
|
|
232
|
+
secondaryStorage: SecondaryStorage | undefined;
|
|
233
|
+
password: {
|
|
234
|
+
hash: (password: string) => Promise<string>;
|
|
235
|
+
verify: (data: { password: string; hash: string }) => Promise<boolean>;
|
|
236
|
+
config: {
|
|
237
|
+
minPasswordLength: number;
|
|
238
|
+
maxPasswordLength: number;
|
|
239
|
+
};
|
|
240
|
+
checkPassword: CheckPasswordFn<Options>;
|
|
241
|
+
};
|
|
242
|
+
tables: BetterAuthDBSchema;
|
|
243
|
+
runMigrations: () => Promise<void>;
|
|
244
|
+
publishTelemetry: (event: {
|
|
245
|
+
type: string;
|
|
246
|
+
anonymousId?: string | undefined;
|
|
247
|
+
payload: Record<string, any>;
|
|
248
|
+
}) => Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* This skips the origin check for all requests.
|
|
251
|
+
*
|
|
252
|
+
* set to true by default for `test` environments and `false`
|
|
253
|
+
* for other environments.
|
|
254
|
+
*
|
|
255
|
+
* It's inferred from the `options.advanced?.disableCSRFCheck`
|
|
256
|
+
* option or `options.advanced?.disableOriginCheck` option.
|
|
257
|
+
*
|
|
258
|
+
* @default false
|
|
259
|
+
*/
|
|
260
|
+
skipOriginCheck: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* This skips the CSRF check for all requests.
|
|
263
|
+
*
|
|
264
|
+
* This is inferred from the `options.advanced?.
|
|
265
|
+
* disableCSRFCheck` option.
|
|
266
|
+
*
|
|
267
|
+
* @default false
|
|
268
|
+
*/
|
|
269
|
+
skipCSRFCheck: boolean;
|
|
270
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CookieOptions } from "better-call";
|
|
2
|
+
|
|
3
|
+
export type BetterAuthCookies = {
|
|
4
|
+
sessionToken: { name: string; options: CookieOptions };
|
|
5
|
+
sessionData: { name: string; options: CookieOptions };
|
|
6
|
+
accountData: { name: string; options: CookieOptions };
|
|
7
|
+
dontRememberToken: { name: string; options: CookieOptions };
|
|
8
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
|
+
export type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
export type {
|
|
3
|
+
AuthContext,
|
|
4
|
+
GenericEndpointContext,
|
|
5
|
+
InternalAdapter,
|
|
6
|
+
} from "./context";
|
|
7
|
+
export type { BetterAuthCookies } from "./cookie";
|
|
1
8
|
export type * from "./helper";
|
|
2
|
-
export type {
|
|
9
|
+
export type {
|
|
10
|
+
BetterAuthAdvancedOptions,
|
|
11
|
+
BetterAuthOptions,
|
|
12
|
+
BetterAuthRateLimitOptions,
|
|
13
|
+
GenerateIdFn,
|
|
14
|
+
} from "./init-options";
|
|
15
|
+
export type { BetterAuthPlugin, HookEndpointContext } from "./plugin";
|
|
16
|
+
export type {
|
|
17
|
+
BetterAuthClientOptions,
|
|
18
|
+
BetterAuthClientPlugin,
|
|
19
|
+
ClientAtomListener,
|
|
20
|
+
ClientFetchOption,
|
|
21
|
+
ClientStore,
|
|
22
|
+
} from "./plugin-client";
|