@voyantjs/auth 0.6.8 → 0.6.9
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/server.d.ts +7 -294
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +59 -17
- package/dist/server.js.map +1 -1
- package/dist/workspace.d.ts +0 -23
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +2 -59
- package/dist/workspace.js.map +1 -1
- package/package.json +3 -3
package/dist/server.d.ts
CHANGED
|
@@ -23,45 +23,6 @@ export interface CreateBetterAuthOptions {
|
|
|
23
23
|
otp: string;
|
|
24
24
|
type: string;
|
|
25
25
|
}) => Promise<void>;
|
|
26
|
-
/** Called to send an organization invitation email. If not provided, logs to console. */
|
|
27
|
-
sendInvitationEmail?: (data: {
|
|
28
|
-
id: string;
|
|
29
|
-
role: string;
|
|
30
|
-
email: string;
|
|
31
|
-
organization: {
|
|
32
|
-
id: string;
|
|
33
|
-
name: string;
|
|
34
|
-
slug: string;
|
|
35
|
-
createdAt: Date;
|
|
36
|
-
logo?: string | null;
|
|
37
|
-
metadata?: Record<string, unknown> | string;
|
|
38
|
-
};
|
|
39
|
-
invitation: {
|
|
40
|
-
id: string;
|
|
41
|
-
organizationId: string;
|
|
42
|
-
email: string;
|
|
43
|
-
role: string;
|
|
44
|
-
status: "pending" | "accepted" | "rejected" | "canceled";
|
|
45
|
-
expiresAt: Date;
|
|
46
|
-
inviterId: string;
|
|
47
|
-
createdAt: Date;
|
|
48
|
-
teamId?: string | null;
|
|
49
|
-
};
|
|
50
|
-
inviter: {
|
|
51
|
-
id: string;
|
|
52
|
-
organizationId: string;
|
|
53
|
-
userId: string;
|
|
54
|
-
role: string;
|
|
55
|
-
createdAt: Date;
|
|
56
|
-
} & {
|
|
57
|
-
user: {
|
|
58
|
-
id: string;
|
|
59
|
-
name: string;
|
|
60
|
-
email: string;
|
|
61
|
-
image?: string | null;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
}, request?: Request) => Promise<void>;
|
|
65
26
|
}
|
|
66
27
|
/**
|
|
67
28
|
* Framework-agnostic Better Auth factory.
|
|
@@ -88,6 +49,11 @@ export declare function createBetterAuth(options?: CreateBetterAuthOptions): imp
|
|
|
88
49
|
sendOnSignUp: false;
|
|
89
50
|
autoSignInAfterVerification: true;
|
|
90
51
|
};
|
|
52
|
+
user: {
|
|
53
|
+
changeEmail: {
|
|
54
|
+
enabled: true;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
91
57
|
socialProviders: {
|
|
92
58
|
google: {
|
|
93
59
|
clientId: string;
|
|
@@ -1242,261 +1208,7 @@ export declare function createBetterAuth(options?: CreateBetterAuthOptions): imp
|
|
|
1242
1208
|
};
|
|
1243
1209
|
};
|
|
1244
1210
|
};
|
|
1245
|
-
},
|
|
1246
|
-
ac: {
|
|
1247
|
-
newRole<K extends "connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac">(statements: import("better-auth/plugins").Subset<K, {
|
|
1248
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1249
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1250
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1251
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1252
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1253
|
-
readonly auditLog: readonly ["read"];
|
|
1254
|
-
readonly settings: readonly ["read", "update"];
|
|
1255
|
-
readonly organization: readonly ["update", "delete"];
|
|
1256
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1257
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1258
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1259
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1260
|
-
}>): {
|
|
1261
|
-
authorize<K_1 extends K>(request: K_1 extends infer T extends K_2 ? { [key in T]?: import("better-auth/plugins").Subset<K, {
|
|
1262
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1263
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1264
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1265
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1266
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1267
|
-
readonly auditLog: readonly ["read"];
|
|
1268
|
-
readonly settings: readonly ["read", "update"];
|
|
1269
|
-
readonly organization: readonly ["update", "delete"];
|
|
1270
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1271
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1272
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1273
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1274
|
-
}>[key] | {
|
|
1275
|
-
actions: import("better-auth/plugins").Subset<K, {
|
|
1276
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1277
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1278
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1279
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1280
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1281
|
-
readonly auditLog: readonly ["read"];
|
|
1282
|
-
readonly settings: readonly ["read", "update"];
|
|
1283
|
-
readonly organization: readonly ["update", "delete"];
|
|
1284
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1285
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1286
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1287
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1288
|
-
}>[key];
|
|
1289
|
-
connector: "OR" | "AND";
|
|
1290
|
-
} | undefined; } : never, connector?: "OR" | "AND"): import("better-auth/plugins").AuthorizeResponse;
|
|
1291
|
-
statements: import("better-auth/plugins").Subset<K, {
|
|
1292
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1293
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1294
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1295
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1296
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1297
|
-
readonly auditLog: readonly ["read"];
|
|
1298
|
-
readonly settings: readonly ["read", "update"];
|
|
1299
|
-
readonly organization: readonly ["update", "delete"];
|
|
1300
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1301
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1302
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1303
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1304
|
-
}>;
|
|
1305
|
-
};
|
|
1306
|
-
statements: {
|
|
1307
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1308
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1309
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1310
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1311
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1312
|
-
readonly auditLog: readonly ["read"];
|
|
1313
|
-
readonly settings: readonly ["read", "update"];
|
|
1314
|
-
readonly organization: readonly ["update", "delete"];
|
|
1315
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1316
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1317
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1318
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1319
|
-
};
|
|
1320
|
-
};
|
|
1321
|
-
roles: {
|
|
1322
|
-
owner: {
|
|
1323
|
-
authorize<K_1 extends "connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1324
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1325
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1326
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1327
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1328
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1329
|
-
readonly auditLog: readonly ["read"];
|
|
1330
|
-
readonly settings: readonly ["read", "update"];
|
|
1331
|
-
readonly organization: readonly ["update", "delete"];
|
|
1332
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1333
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1334
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1335
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1336
|
-
}>[key] | {
|
|
1337
|
-
actions: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1338
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1339
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1340
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1341
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1342
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1343
|
-
readonly auditLog: readonly ["read"];
|
|
1344
|
-
readonly settings: readonly ["read", "update"];
|
|
1345
|
-
readonly organization: readonly ["update", "delete"];
|
|
1346
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1347
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1348
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1349
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1350
|
-
}>[key];
|
|
1351
|
-
connector: "OR" | "AND";
|
|
1352
|
-
} | undefined; } : never, connector?: "OR" | "AND"): import("better-auth/plugins").AuthorizeResponse;
|
|
1353
|
-
statements: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1354
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1355
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1356
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1357
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1358
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1359
|
-
readonly auditLog: readonly ["read"];
|
|
1360
|
-
readonly settings: readonly ["read", "update"];
|
|
1361
|
-
readonly organization: readonly ["update", "delete"];
|
|
1362
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1363
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1364
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1365
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1366
|
-
}>;
|
|
1367
|
-
};
|
|
1368
|
-
admin: {
|
|
1369
|
-
authorize<K_1 extends "connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1370
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1371
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1372
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1373
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1374
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1375
|
-
readonly auditLog: readonly ["read"];
|
|
1376
|
-
readonly settings: readonly ["read", "update"];
|
|
1377
|
-
readonly organization: readonly ["update", "delete"];
|
|
1378
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1379
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1380
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1381
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1382
|
-
}>[key] | {
|
|
1383
|
-
actions: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1384
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1385
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1386
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1387
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1388
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1389
|
-
readonly auditLog: readonly ["read"];
|
|
1390
|
-
readonly settings: readonly ["read", "update"];
|
|
1391
|
-
readonly organization: readonly ["update", "delete"];
|
|
1392
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1393
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1394
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1395
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1396
|
-
}>[key];
|
|
1397
|
-
connector: "OR" | "AND";
|
|
1398
|
-
} | undefined; } : never, connector?: "OR" | "AND"): import("better-auth/plugins").AuthorizeResponse;
|
|
1399
|
-
statements: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1400
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1401
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1402
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1403
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1404
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1405
|
-
readonly auditLog: readonly ["read"];
|
|
1406
|
-
readonly settings: readonly ["read", "update"];
|
|
1407
|
-
readonly organization: readonly ["update", "delete"];
|
|
1408
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1409
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1410
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1411
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1412
|
-
}>;
|
|
1413
|
-
};
|
|
1414
|
-
member: {
|
|
1415
|
-
authorize<K_1 extends "connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac">(request: K_1 extends infer T extends K ? { [key in T]?: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1416
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1417
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1418
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1419
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1420
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1421
|
-
readonly auditLog: readonly ["read"];
|
|
1422
|
-
readonly settings: readonly ["read", "update"];
|
|
1423
|
-
readonly organization: readonly ["update", "delete"];
|
|
1424
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1425
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1426
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1427
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1428
|
-
}>[key] | {
|
|
1429
|
-
actions: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1430
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1431
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1432
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1433
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1434
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1435
|
-
readonly auditLog: readonly ["read"];
|
|
1436
|
-
readonly settings: readonly ["read", "update"];
|
|
1437
|
-
readonly organization: readonly ["update", "delete"];
|
|
1438
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1439
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1440
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1441
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1442
|
-
}>[key];
|
|
1443
|
-
connector: "OR" | "AND";
|
|
1444
|
-
} | undefined; } : never, connector?: "OR" | "AND"): import("better-auth/plugins").AuthorizeResponse;
|
|
1445
|
-
statements: import("better-auth/plugins").Subset<"connection" | "organization" | "member" | "invitation" | "operator" | "oauthClient" | "apiKey" | "operatorGrant" | "auditLog" | "settings" | "team" | "ac", {
|
|
1446
|
-
readonly operator: readonly ["create", "read", "update", "delete"];
|
|
1447
|
-
readonly connection: readonly ["create", "read", "update", "delete"];
|
|
1448
|
-
readonly oauthClient: readonly ["create", "read", "revoke"];
|
|
1449
|
-
readonly apiKey: readonly ["create", "read", "update", "delete"];
|
|
1450
|
-
readonly operatorGrant: readonly ["create", "read", "update", "delete"];
|
|
1451
|
-
readonly auditLog: readonly ["read"];
|
|
1452
|
-
readonly settings: readonly ["read", "update"];
|
|
1453
|
-
readonly organization: readonly ["update", "delete"];
|
|
1454
|
-
readonly member: readonly ["create", "update", "delete"];
|
|
1455
|
-
readonly invitation: readonly ["create", "cancel"];
|
|
1456
|
-
readonly team: readonly ["create", "update", "delete"];
|
|
1457
|
-
readonly ac: readonly ["create", "read", "update", "delete"];
|
|
1458
|
-
}>;
|
|
1459
|
-
};
|
|
1460
|
-
};
|
|
1461
|
-
sendInvitationEmail: (data: {
|
|
1462
|
-
id: string;
|
|
1463
|
-
role: string;
|
|
1464
|
-
email: string;
|
|
1465
|
-
organization: {
|
|
1466
|
-
id: string;
|
|
1467
|
-
name: string;
|
|
1468
|
-
slug: string;
|
|
1469
|
-
createdAt: Date;
|
|
1470
|
-
logo?: string | null;
|
|
1471
|
-
metadata?: Record<string, unknown> | string;
|
|
1472
|
-
};
|
|
1473
|
-
invitation: {
|
|
1474
|
-
id: string;
|
|
1475
|
-
organizationId: string;
|
|
1476
|
-
email: string;
|
|
1477
|
-
role: string;
|
|
1478
|
-
status: "pending" | "accepted" | "rejected" | "canceled";
|
|
1479
|
-
expiresAt: Date;
|
|
1480
|
-
inviterId: string;
|
|
1481
|
-
createdAt: Date;
|
|
1482
|
-
teamId?: string | null;
|
|
1483
|
-
};
|
|
1484
|
-
inviter: {
|
|
1485
|
-
id: string;
|
|
1486
|
-
organizationId: string;
|
|
1487
|
-
userId: string;
|
|
1488
|
-
role: string;
|
|
1489
|
-
createdAt: Date;
|
|
1490
|
-
} & {
|
|
1491
|
-
user: {
|
|
1492
|
-
id: string;
|
|
1493
|
-
name: string;
|
|
1494
|
-
email: string;
|
|
1495
|
-
image?: string | null;
|
|
1496
|
-
};
|
|
1497
|
-
};
|
|
1498
|
-
}, request?: Request) => Promise<void>;
|
|
1499
|
-
}>, {
|
|
1211
|
+
}, {
|
|
1500
1212
|
id: "email-otp";
|
|
1501
1213
|
init(ctx: import("better-auth").AuthContext): {
|
|
1502
1214
|
options: {
|
|
@@ -2030,6 +1742,7 @@ export declare function createBetterAuth(options?: CreateBetterAuthOptions): imp
|
|
|
2030
1742
|
databaseHooks: {
|
|
2031
1743
|
user: {
|
|
2032
1744
|
create: {
|
|
1745
|
+
before: () => Promise<void>;
|
|
2033
1746
|
after: (user: {
|
|
2034
1747
|
id: string;
|
|
2035
1748
|
createdAt: Date;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAYpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGzD,wBAAgB,aAAa,IAAI,MAAM,CAetC;AA6CD,MAAM,WAAW,uBAAuB;IACtC,EAAE,CAAC,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE;QACzB,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;QACrC,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnB,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5F;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,GAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAD7iL"}
|
package/dist/server.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { apiKey } from "@better-auth/api-key";
|
|
2
2
|
import { getDb } from "@voyantjs/db";
|
|
3
|
-
import { apikeyTable, authAccount,
|
|
3
|
+
import { apikeyTable, authAccount, authSession, authUser, authVerification, userProfilesTable, } from "@voyantjs/db/schema/iam";
|
|
4
4
|
import { betterAuth } from "better-auth";
|
|
5
5
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
6
|
-
import { emailOTP
|
|
7
|
-
import {
|
|
6
|
+
import { emailOTP } from "better-auth/plugins";
|
|
7
|
+
import { sql } from "drizzle-orm";
|
|
8
8
|
export function getAuthSecret() {
|
|
9
9
|
const secret = process.env.BETTER_AUTH_SECRET || process.env.SESSION_CLAIMS_SECRET || "";
|
|
10
10
|
if (!secret || secret.length < 32) {
|
|
@@ -28,6 +28,35 @@ function getTrustedOrigins() {
|
|
|
28
28
|
].filter((value) => typeof value === "string" && value.trim().length > 0);
|
|
29
29
|
return Array.from(new Set(values.map((value) => value.trim().replace(/\/$/, ""))));
|
|
30
30
|
}
|
|
31
|
+
const LOCAL_WILDCARDS = [
|
|
32
|
+
"http://localhost:*",
|
|
33
|
+
"http://127.0.0.1:*",
|
|
34
|
+
"https://localhost:*",
|
|
35
|
+
"https://127.0.0.1:*",
|
|
36
|
+
];
|
|
37
|
+
function hasLocalOrigin(origins, baseURL) {
|
|
38
|
+
const all = [...origins, baseURL];
|
|
39
|
+
return all.some((value) => {
|
|
40
|
+
try {
|
|
41
|
+
const { hostname } = new URL(value);
|
|
42
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* If the app is running against a localhost baseURL (dev), allow any localhost
|
|
51
|
+
* origin/port so second dev servers (e.g. Vite on :3301 hitting API on :3200)
|
|
52
|
+
* aren't rejected by Better Auth's origin check. Production origins are
|
|
53
|
+
* unaffected — the wildcards are only added when we already see localhost.
|
|
54
|
+
*/
|
|
55
|
+
function expandTrustedOrigins(origins, baseURL) {
|
|
56
|
+
if (!hasLocalOrigin(origins, baseURL))
|
|
57
|
+
return origins;
|
|
58
|
+
return Array.from(new Set([...origins, ...LOCAL_WILDCARDS]));
|
|
59
|
+
}
|
|
31
60
|
/**
|
|
32
61
|
* Framework-agnostic Better Auth factory.
|
|
33
62
|
*
|
|
@@ -42,7 +71,7 @@ export function createBetterAuth(options = {}) {
|
|
|
42
71
|
process.env.APP_URL ??
|
|
43
72
|
process.env.NEXT_PUBLIC_APP_URL ??
|
|
44
73
|
"http://localhost:3000";
|
|
45
|
-
const trustedOrigins = options.trustedOrigins ?? getTrustedOrigins();
|
|
74
|
+
const trustedOrigins = expandTrustedOrigins(options.trustedOrigins ?? getTrustedOrigins(), baseURL);
|
|
46
75
|
const extraPlugins = options.plugins ?? [];
|
|
47
76
|
return betterAuth({
|
|
48
77
|
appName: "Voyant",
|
|
@@ -57,9 +86,6 @@ export function createBetterAuth(options = {}) {
|
|
|
57
86
|
account: authAccount,
|
|
58
87
|
verification: authVerification,
|
|
59
88
|
apikey: apikeyTable,
|
|
60
|
-
organization: authOrganization,
|
|
61
|
-
member: authMember,
|
|
62
|
-
invitation: authInvitation,
|
|
63
89
|
},
|
|
64
90
|
}),
|
|
65
91
|
emailAndPassword: {
|
|
@@ -78,6 +104,11 @@ export function createBetterAuth(options = {}) {
|
|
|
78
104
|
sendOnSignUp: false, // OTP plugin handles this
|
|
79
105
|
autoSignInAfterVerification: true,
|
|
80
106
|
},
|
|
107
|
+
user: {
|
|
108
|
+
changeEmail: {
|
|
109
|
+
enabled: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
81
112
|
socialProviders: {
|
|
82
113
|
google: {
|
|
83
114
|
clientId: process.env.GOOGLE_CLIENT_ID || "",
|
|
@@ -90,16 +121,6 @@ export function createBetterAuth(options = {}) {
|
|
|
90
121
|
apiKey({
|
|
91
122
|
defaultPrefix: "voy_",
|
|
92
123
|
apiKeyHeaders: ["authorization"],
|
|
93
|
-
references: "organization",
|
|
94
|
-
}),
|
|
95
|
-
organization({
|
|
96
|
-
ac,
|
|
97
|
-
roles,
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
99
|
-
sendInvitationEmail: options.sendInvitationEmail ??
|
|
100
|
-
(async (data) => {
|
|
101
|
-
console.warn(`[Auth] Invitation for ${data.email} to org ${data.organization.name}`);
|
|
102
|
-
}),
|
|
103
124
|
}),
|
|
104
125
|
emailOTP({
|
|
105
126
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
@@ -110,16 +131,36 @@ export function createBetterAuth(options = {}) {
|
|
|
110
131
|
otpLength: 6,
|
|
111
132
|
expiresIn: 600,
|
|
112
133
|
sendVerificationOnSignUp: true,
|
|
134
|
+
changeEmail: {
|
|
135
|
+
enabled: true,
|
|
136
|
+
},
|
|
113
137
|
}),
|
|
114
138
|
...extraPlugins,
|
|
115
139
|
],
|
|
116
140
|
databaseHooks: {
|
|
117
141
|
user: {
|
|
118
142
|
create: {
|
|
143
|
+
// Single-tenant: once a user exists, reject any new-user creation.
|
|
144
|
+
// Covers email sign-up AND social-provider sign-up (Google would
|
|
145
|
+
// otherwise auto-create a user on first OAuth callback). Existing
|
|
146
|
+
// social sign-ins still work because this hook only fires on CREATE.
|
|
147
|
+
// Seed scripts do raw drizzle inserts, so they bypass this hook —
|
|
148
|
+
// which is intentional.
|
|
149
|
+
before: async () => {
|
|
150
|
+
const [row] = await db.select({ count: sql `count(*)::int` }).from(authUser);
|
|
151
|
+
if ((row?.count ?? 0) > 0) {
|
|
152
|
+
throw new Error("Sign-up is disabled. Ask an admin to invite you.");
|
|
153
|
+
}
|
|
154
|
+
},
|
|
119
155
|
after: async (user) => {
|
|
120
156
|
const nameParts = user.name?.split(" ") ?? [];
|
|
121
157
|
const firstName = nameParts[0] ?? null;
|
|
122
158
|
const lastName = nameParts.length > 1 ? nameParts.slice(1).join(" ") : null;
|
|
159
|
+
// Single-tenant bootstrap: the very first user to register becomes
|
|
160
|
+
// the super-admin. Runs atomically after the `user` row is
|
|
161
|
+
// inserted, so a simple COUNT(*) = 1 check identifies them.
|
|
162
|
+
const [countRow] = await db.select({ count: sql `count(*)::int` }).from(authUser);
|
|
163
|
+
const isFirstUser = (countRow?.count ?? 0) === 1;
|
|
123
164
|
await db
|
|
124
165
|
.insert(userProfilesTable)
|
|
125
166
|
.values({
|
|
@@ -127,6 +168,7 @@ export function createBetterAuth(options = {}) {
|
|
|
127
168
|
firstName,
|
|
128
169
|
lastName,
|
|
129
170
|
avatarUrl: user.image ?? null,
|
|
171
|
+
isSuperAdmin: isFirstUser,
|
|
130
172
|
})
|
|
131
173
|
.onConflictDoNothing();
|
|
132
174
|
},
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EACL,WAAW,EACX,WAAW,EACX,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,M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E,EAAE;wBACpB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;wBAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;wBACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;wBAE3E,mEAAmE;wBACnE,2DAA2D;wBAC3D,4DAA4D;wBAC5D,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,CAAQ,eAAe,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;wBACxF,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC,CAAA;wBAEhD,MAAM,EAAE;6BACL,MAAM,CAAC,iBAAiB,CAAC;6BACzB,MAAM,CAAC;4BACN,EAAE,EAAE,IAAI,CAAC,EAAE;4BACX,SAAS;4BACT,QAAQ;4BACR,SAAS,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI;4BAC7B,YAAY,EAAE,WAAW;yBAC1B,CAAC;6BACD,mBAAmB,EAAE,CAAA;oBAC1B,CAAC;iBACF;aACF;SACF;QACD,QAAQ,EAAE;YACR,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;SACxD;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { getDb } from "@voyantjs/db";
|
|
2
2
|
type WorkspaceDb = ReturnType<typeof getDb>;
|
|
3
|
-
export type WorkspaceOrganization = {
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
slug: string;
|
|
7
|
-
logo?: string | null;
|
|
8
|
-
};
|
|
9
|
-
export type CurrentWorkspace = {
|
|
10
|
-
organizations: WorkspaceOrganization[];
|
|
11
|
-
activeOrganization: WorkspaceOrganization | null;
|
|
12
|
-
};
|
|
13
3
|
export type CurrentUser = {
|
|
14
4
|
id: string;
|
|
15
5
|
email: string;
|
|
@@ -19,27 +9,14 @@ export type CurrentUser = {
|
|
|
19
9
|
isSupportUser: boolean;
|
|
20
10
|
createdAt: string;
|
|
21
11
|
profilePictureUrl?: string | null;
|
|
22
|
-
activeOrganizationId?: string | null;
|
|
23
12
|
};
|
|
24
13
|
export type AuthStatus = {
|
|
25
14
|
userExists: boolean;
|
|
26
15
|
authenticated: boolean;
|
|
27
16
|
reason?: string;
|
|
28
17
|
};
|
|
29
|
-
export declare function listWorkspaceOrganizations(db: WorkspaceDb, userId: string): Promise<WorkspaceOrganization[]>;
|
|
30
|
-
export declare function getCurrentWorkspace(db: WorkspaceDb, input: {
|
|
31
|
-
sessionId: string;
|
|
32
|
-
userId: string;
|
|
33
|
-
activeOrganizationId: string | null;
|
|
34
|
-
}): Promise<CurrentWorkspace>;
|
|
35
|
-
export declare function setActiveWorkspaceOrganization(db: WorkspaceDb, input: {
|
|
36
|
-
sessionId: string;
|
|
37
|
-
userId: string;
|
|
38
|
-
organizationId: string;
|
|
39
|
-
}): Promise<CurrentWorkspace | null>;
|
|
40
18
|
export declare function getCurrentUser(db: WorkspaceDb, input: {
|
|
41
19
|
userId: string;
|
|
42
|
-
activeOrganizationId: string | null;
|
|
43
20
|
}): Promise<CurrentUser | null>;
|
|
44
21
|
export declare function ensureCurrentUserProfile(db: WorkspaceDb, userId: string): Promise<AuthStatus>;
|
|
45
22
|
export {};
|
package/dist/workspace.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAIzC,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAA;AAE3C,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,YAAY,EAAE,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,OAAO,CAAA;IACnB,aAAa,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,WAAW,EACf,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GACxB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CA+B7B;AAED,wBAAsB,wBAAwB,CAC5C,EAAE,EAAE,WAAW,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,CA6CrB"}
|
package/dist/workspace.js
CHANGED
|
@@ -1,61 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export async function listWorkspaceOrganizations(db, userId) {
|
|
4
|
-
return db
|
|
5
|
-
.select({
|
|
6
|
-
id: authOrganization.id,
|
|
7
|
-
name: authOrganization.name,
|
|
8
|
-
slug: authOrganization.slug,
|
|
9
|
-
logo: authOrganization.logo,
|
|
10
|
-
})
|
|
11
|
-
.from(authMember)
|
|
12
|
-
.innerJoin(authOrganization, eq(authOrganization.id, authMember.organizationId))
|
|
13
|
-
.where(eq(authMember.userId, userId))
|
|
14
|
-
.orderBy(asc(authOrganization.createdAt));
|
|
15
|
-
}
|
|
16
|
-
export async function getCurrentWorkspace(db, input) {
|
|
17
|
-
const organizations = await listWorkspaceOrganizations(db, input.userId);
|
|
18
|
-
if (organizations.length === 0) {
|
|
19
|
-
return {
|
|
20
|
-
organizations,
|
|
21
|
-
activeOrganization: null,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
let activeOrganizationId = organizations.find((organization) => organization.id === input.activeOrganizationId)?.id ?? null;
|
|
25
|
-
if (!activeOrganizationId) {
|
|
26
|
-
activeOrganizationId = organizations[0]?.id ?? null;
|
|
27
|
-
if (activeOrganizationId) {
|
|
28
|
-
await db
|
|
29
|
-
.update(authSession)
|
|
30
|
-
.set({ activeOrganizationId, updatedAt: new Date() })
|
|
31
|
-
.where(eq(authSession.id, input.sessionId));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
organizations,
|
|
36
|
-
activeOrganization: organizations.find((organization) => organization.id === activeOrganizationId) ?? null,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export async function setActiveWorkspaceOrganization(db, input) {
|
|
40
|
-
const [membership] = await db
|
|
41
|
-
.select({ id: authOrganization.id })
|
|
42
|
-
.from(authMember)
|
|
43
|
-
.innerJoin(authOrganization, eq(authOrganization.id, authMember.organizationId))
|
|
44
|
-
.where(and(eq(authMember.userId, input.userId), eq(authMember.organizationId, input.organizationId)))
|
|
45
|
-
.limit(1);
|
|
46
|
-
if (!membership) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
await db
|
|
50
|
-
.update(authSession)
|
|
51
|
-
.set({ activeOrganizationId: input.organizationId, updatedAt: new Date() })
|
|
52
|
-
.where(eq(authSession.id, input.sessionId));
|
|
53
|
-
return getCurrentWorkspace(db, {
|
|
54
|
-
sessionId: input.sessionId,
|
|
55
|
-
userId: input.userId,
|
|
56
|
-
activeOrganizationId: input.organizationId,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
1
|
+
import { authUser, userProfilesTable } from "@voyantjs/db/schema/iam";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
59
3
|
export async function getCurrentUser(db, input) {
|
|
60
4
|
const [row] = await db
|
|
61
5
|
.select({
|
|
@@ -84,7 +28,6 @@ export async function getCurrentUser(db, input) {
|
|
|
84
28
|
isSupportUser: row.isSupportUser ?? false,
|
|
85
29
|
createdAt: row.createdAt?.toISOString() ?? new Date().toISOString(),
|
|
86
30
|
profilePictureUrl: row.avatarUrl ?? null,
|
|
87
|
-
activeOrganizationId: input.activeOrganizationId,
|
|
88
31
|
};
|
|
89
32
|
}
|
|
90
33
|
export async function ensureCurrentUserProfile(db, userId) {
|
package/dist/workspace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAqBhC,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,EAAe,EACf,KAAyB;IAEzB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE;SACnB,MAAM,CAAC;QACN,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,iBAAiB,CAAC,SAAS;QACtC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;QACpC,SAAS,EAAE,iBAAiB,CAAC,SAAS;QACtC,YAAY,EAAE,iBAAiB,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AK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAEtE,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,aAAa,EAAE,IAAI;YACnB,MAAM,EAAE,uBAAuB,OAAO,EAAE;SACzC,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/auth",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"license": "FSL-1.1-Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@better-auth/api-key": "^1.5.6",
|
|
48
48
|
"better-auth": "^1.5.6",
|
|
49
49
|
"drizzle-orm": "^0.45.2",
|
|
50
|
-
"@voyantjs/db": "0.6.
|
|
51
|
-
"@voyantjs/utils": "0.6.
|
|
50
|
+
"@voyantjs/db": "0.6.9",
|
|
51
|
+
"@voyantjs/utils": "0.6.9"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "25.5.2",
|