better-auth 0.4.0 → 0.4.2-beta.1
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/.DS_Store +0 -0
- package/dist/cli.js +4 -4
- package/dist/client/plugins.d.ts +197 -5
- package/dist/client/plugins.js +9 -0
- package/package.json +3 -2
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/cli.js
CHANGED
|
@@ -267,7 +267,7 @@ var createKyselyAdapter = async (config) => {
|
|
|
267
267
|
};
|
|
268
268
|
|
|
269
269
|
// src/cli/commands/migrate.ts
|
|
270
|
-
import
|
|
270
|
+
import yoctoSpinner from "yocto-spinner";
|
|
271
271
|
import chalk from "chalk";
|
|
272
272
|
import prompts from "prompts";
|
|
273
273
|
|
|
@@ -726,7 +726,7 @@ var migrate = new Command("migrate").option(
|
|
|
726
726
|
);
|
|
727
727
|
process.exit(1);
|
|
728
728
|
}
|
|
729
|
-
const spinner =
|
|
729
|
+
const spinner = yoctoSpinner({ text: "preparing migration..." }).start();
|
|
730
730
|
const { toBeAdded, toBeCreated, runMigrations } = await getMigrations(config);
|
|
731
731
|
if (!toBeAdded.length && !toBeCreated.length) {
|
|
732
732
|
spinner.stop();
|
|
@@ -766,7 +766,7 @@ import { Command as Command2 } from "commander";
|
|
|
766
766
|
import { z as z2 } from "zod";
|
|
767
767
|
import { existsSync as existsSync3 } from "fs";
|
|
768
768
|
import path4 from "path";
|
|
769
|
-
import
|
|
769
|
+
import yoctoSpinner2 from "yocto-spinner";
|
|
770
770
|
import prompts2 from "prompts";
|
|
771
771
|
|
|
772
772
|
// src/adapters/kysely-adapter/index.ts
|
|
@@ -1105,7 +1105,7 @@ var generate = new Command2("generate").option(
|
|
|
1105
1105
|
);
|
|
1106
1106
|
return;
|
|
1107
1107
|
}
|
|
1108
|
-
const spinner =
|
|
1108
|
+
const spinner = yoctoSpinner2({ text: "preparing schema..." }).start();
|
|
1109
1109
|
const adapter = await getAdapter(config, true).catch((e) => {
|
|
1110
1110
|
logger.error(e.message);
|
|
1111
1111
|
process.exit(1);
|
package/dist/client/plugins.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { o as organization, j as Organization, M as Member, I as Invitation, u a
|
|
|
6
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
8
|
import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-C6jmDLjB.js';
|
|
9
|
-
import '
|
|
10
|
-
import 'zod';
|
|
11
|
-
import '
|
|
12
|
-
import '
|
|
9
|
+
import * as better_call from 'better-call';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { U as User } from '../types-Bs23H3QM.js';
|
|
12
|
+
import { OAuth2Tokens } from 'arctic';
|
|
13
13
|
import '@simplewebauthn/types';
|
|
14
14
|
import 'kysely';
|
|
15
15
|
import 'better-sqlite3';
|
|
@@ -256,4 +256,196 @@ declare const adminClient: () => {
|
|
|
256
256
|
$InferServerPlugin: ReturnType<typeof admin>;
|
|
257
257
|
};
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Configuration interface for generic OAuth providers.
|
|
261
|
+
*/
|
|
262
|
+
interface GenericOAuthConfig {
|
|
263
|
+
/** Unique identifier for the OAuth provider */
|
|
264
|
+
providerId: string;
|
|
265
|
+
/**
|
|
266
|
+
* URL to fetch OAuth 2.0 configuration.
|
|
267
|
+
* If provided, the authorization and token endpoints will be fetched from this URL.
|
|
268
|
+
*/
|
|
269
|
+
discoveryUrl?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Type of OAuth flow.
|
|
272
|
+
* @default "oauth2"
|
|
273
|
+
*/
|
|
274
|
+
type?: "oauth2" | "oidc";
|
|
275
|
+
/**
|
|
276
|
+
* URL for the authorization endpoint.
|
|
277
|
+
* Optional if using discoveryUrl.
|
|
278
|
+
*/
|
|
279
|
+
authorizationUrl?: string;
|
|
280
|
+
/**
|
|
281
|
+
* URL for the token endpoint.
|
|
282
|
+
* Optional if using discoveryUrl.
|
|
283
|
+
*/
|
|
284
|
+
tokenUrl?: string;
|
|
285
|
+
/**
|
|
286
|
+
* URL for the user info endpoint.
|
|
287
|
+
* Optional if using discoveryUrl.
|
|
288
|
+
*/
|
|
289
|
+
userInfoUrl?: string;
|
|
290
|
+
/** OAuth client ID */
|
|
291
|
+
clientId: string;
|
|
292
|
+
/** OAuth client secret */
|
|
293
|
+
clientSecret: string;
|
|
294
|
+
/**
|
|
295
|
+
* Array of OAuth scopes to request.
|
|
296
|
+
* @default []
|
|
297
|
+
*/
|
|
298
|
+
scopes?: string[];
|
|
299
|
+
/**
|
|
300
|
+
* Custom redirect URI.
|
|
301
|
+
* If not provided, a default URI will be constructed.
|
|
302
|
+
*/
|
|
303
|
+
redirectURI?: string;
|
|
304
|
+
/**
|
|
305
|
+
* OAuth response type.
|
|
306
|
+
* @default "code"
|
|
307
|
+
*/
|
|
308
|
+
responseType?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Prompt parameter for the authorization request.
|
|
311
|
+
* Controls the authentication experience for the user.
|
|
312
|
+
*/
|
|
313
|
+
prompt?: string;
|
|
314
|
+
/**
|
|
315
|
+
* Whether to use PKCE (Proof Key for Code Exchange)
|
|
316
|
+
* @default false
|
|
317
|
+
*/
|
|
318
|
+
pkce?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Access type for the authorization request.
|
|
321
|
+
* Use "offline" to request a refresh token.
|
|
322
|
+
*/
|
|
323
|
+
accessType?: string;
|
|
324
|
+
/**
|
|
325
|
+
* Custom function to fetch user info.
|
|
326
|
+
* If provided, this function will be used instead of the default user info fetching logic.
|
|
327
|
+
* @param tokens - The OAuth tokens received after successful authentication
|
|
328
|
+
* @returns A promise that resolves to a User object or null
|
|
329
|
+
*/
|
|
330
|
+
getUserInfo?: (tokens: OAuth2Tokens) => Promise<User | null>;
|
|
331
|
+
}
|
|
332
|
+
interface GenericOAuthOptions {
|
|
333
|
+
/**
|
|
334
|
+
* Array of OAuth provider configurations.
|
|
335
|
+
*/
|
|
336
|
+
config: GenericOAuthConfig[];
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* A generic OAuth plugin that can be used to add OAuth support to any provider
|
|
340
|
+
*/
|
|
341
|
+
declare const genericOAuth: (options: GenericOAuthOptions) => {
|
|
342
|
+
id: "generic-oauth";
|
|
343
|
+
endpoints: {
|
|
344
|
+
signInWithOAuth2: {
|
|
345
|
+
<C extends [better_call.Context<"/sign-in/oauth2", {
|
|
346
|
+
method: "POST";
|
|
347
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
348
|
+
/**
|
|
349
|
+
* Redirect to the current URL after the
|
|
350
|
+
* user has signed in.
|
|
351
|
+
*/
|
|
352
|
+
currentURL: z.ZodOptional<z.ZodString>;
|
|
353
|
+
}, "strip", z.ZodTypeAny, {
|
|
354
|
+
currentURL?: string | undefined;
|
|
355
|
+
}, {
|
|
356
|
+
currentURL?: string | undefined;
|
|
357
|
+
}>>;
|
|
358
|
+
body: z.ZodObject<{
|
|
359
|
+
providerId: z.ZodString;
|
|
360
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
361
|
+
}, "strip", z.ZodTypeAny, {
|
|
362
|
+
providerId: string;
|
|
363
|
+
callbackURL?: string | undefined;
|
|
364
|
+
}, {
|
|
365
|
+
providerId: string;
|
|
366
|
+
callbackURL?: string | undefined;
|
|
367
|
+
}>;
|
|
368
|
+
}>]>(...ctx: C): Promise<C extends [{
|
|
369
|
+
asResponse: true;
|
|
370
|
+
}] ? Response : {
|
|
371
|
+
url: string;
|
|
372
|
+
state: string;
|
|
373
|
+
codeVerifier: string;
|
|
374
|
+
redirect: boolean;
|
|
375
|
+
}>;
|
|
376
|
+
path: "/sign-in/oauth2";
|
|
377
|
+
options: {
|
|
378
|
+
method: "POST";
|
|
379
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
380
|
+
/**
|
|
381
|
+
* Redirect to the current URL after the
|
|
382
|
+
* user has signed in.
|
|
383
|
+
*/
|
|
384
|
+
currentURL: z.ZodOptional<z.ZodString>;
|
|
385
|
+
}, "strip", z.ZodTypeAny, {
|
|
386
|
+
currentURL?: string | undefined;
|
|
387
|
+
}, {
|
|
388
|
+
currentURL?: string | undefined;
|
|
389
|
+
}>>;
|
|
390
|
+
body: z.ZodObject<{
|
|
391
|
+
providerId: z.ZodString;
|
|
392
|
+
callbackURL: z.ZodOptional<z.ZodString>;
|
|
393
|
+
}, "strip", z.ZodTypeAny, {
|
|
394
|
+
providerId: string;
|
|
395
|
+
callbackURL?: string | undefined;
|
|
396
|
+
}, {
|
|
397
|
+
providerId: string;
|
|
398
|
+
callbackURL?: string | undefined;
|
|
399
|
+
}>;
|
|
400
|
+
};
|
|
401
|
+
method: better_call.Method | better_call.Method[];
|
|
402
|
+
headers: Headers;
|
|
403
|
+
};
|
|
404
|
+
oAuth2Callback: {
|
|
405
|
+
<C extends [better_call.Context<"/oauth2/callback/:providerId", {
|
|
406
|
+
method: "GET";
|
|
407
|
+
query: z.ZodObject<{
|
|
408
|
+
code: z.ZodOptional<z.ZodString>;
|
|
409
|
+
error: z.ZodOptional<z.ZodString>;
|
|
410
|
+
state: z.ZodString;
|
|
411
|
+
}, "strip", z.ZodTypeAny, {
|
|
412
|
+
state: string;
|
|
413
|
+
code?: string | undefined;
|
|
414
|
+
error?: string | undefined;
|
|
415
|
+
}, {
|
|
416
|
+
state: string;
|
|
417
|
+
code?: string | undefined;
|
|
418
|
+
error?: string | undefined;
|
|
419
|
+
}>;
|
|
420
|
+
}>]>(...ctx: C): Promise<C extends [{
|
|
421
|
+
asResponse: true;
|
|
422
|
+
}] ? Response : never>;
|
|
423
|
+
path: "/oauth2/callback/:providerId";
|
|
424
|
+
options: {
|
|
425
|
+
method: "GET";
|
|
426
|
+
query: z.ZodObject<{
|
|
427
|
+
code: z.ZodOptional<z.ZodString>;
|
|
428
|
+
error: z.ZodOptional<z.ZodString>;
|
|
429
|
+
state: z.ZodString;
|
|
430
|
+
}, "strip", z.ZodTypeAny, {
|
|
431
|
+
state: string;
|
|
432
|
+
code?: string | undefined;
|
|
433
|
+
error?: string | undefined;
|
|
434
|
+
}, {
|
|
435
|
+
state: string;
|
|
436
|
+
code?: string | undefined;
|
|
437
|
+
error?: string | undefined;
|
|
438
|
+
}>;
|
|
439
|
+
};
|
|
440
|
+
method: better_call.Method | better_call.Method[];
|
|
441
|
+
headers: Headers;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
declare const genericOAuthClient: () => {
|
|
447
|
+
id: "generic-oauth-client";
|
|
448
|
+
$InferServerPlugin: ReturnType<typeof genericOAuth>;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export { adminClient, anonymousClient, genericOAuthClient, inferAdditionalFields, magicLinkClient, organizationClient, phoneNumberClient, usernameClient };
|
package/dist/client/plugins.js
CHANGED
|
@@ -522,9 +522,18 @@ var adminClient = () => {
|
|
|
522
522
|
$InferServerPlugin: {}
|
|
523
523
|
};
|
|
524
524
|
};
|
|
525
|
+
|
|
526
|
+
// src/plugins/generic-oauth/client.ts
|
|
527
|
+
var genericOAuthClient = () => {
|
|
528
|
+
return {
|
|
529
|
+
id: "generic-oauth-client",
|
|
530
|
+
$InferServerPlugin: {}
|
|
531
|
+
};
|
|
532
|
+
};
|
|
525
533
|
export {
|
|
526
534
|
adminClient,
|
|
527
535
|
anonymousClient,
|
|
536
|
+
genericOAuthClient,
|
|
528
537
|
getPasskeyActions,
|
|
529
538
|
inferAdditionalFields,
|
|
530
539
|
magicLinkClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2-beta.1",
|
|
4
4
|
"description": "The most comprehensive authentication library for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -89,7 +89,6 @@
|
|
|
89
89
|
"consola": "^3.2.3",
|
|
90
90
|
"defu": "^6.1.4",
|
|
91
91
|
"dotenv": "^16.4.5",
|
|
92
|
-
"execa": "^9.4.0",
|
|
93
92
|
"jose": "^5.7.0",
|
|
94
93
|
"kysely": "^0.27.4",
|
|
95
94
|
"nanoid": "^5.0.7",
|
|
@@ -98,6 +97,8 @@
|
|
|
98
97
|
"ora": "^8.0.1",
|
|
99
98
|
"oslo": "^1.2.1",
|
|
100
99
|
"prompts": "^2.4.2",
|
|
100
|
+
"tinyexec": "^0.3.0",
|
|
101
|
+
"yocto-spinner": "^0.1.1",
|
|
101
102
|
"zod": "^3.22.5"
|
|
102
103
|
},
|
|
103
104
|
"files": [
|