better-auth 0.4.4 → 0.4.5
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/adapters/drizzle.d.ts +1 -1
- package/dist/adapters/mongodb.d.ts +1 -1
- package/dist/adapters/prisma.d.ts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +119 -101
- package/dist/client/plugins.d.ts +3 -3
- package/dist/client.d.ts +1 -1
- package/dist/{index-CJ44EC0j.d.ts → index-45sX2yHG.d.ts} +52 -2
- package/dist/{index-Bt0CUdx4.d.ts → index-B5SM-JCa.d.ts} +38 -38
- package/dist/index.d.ts +1 -1
- package/dist/index.js +146 -120
- package/dist/next-js.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/plugins.d.ts +3 -3
- package/dist/plugins.js +149 -113
- package/dist/react.d.ts +1 -1
- package/dist/solid-start.d.ts +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/svelte-kit.d.ts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/vue.d.ts +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-
|
|
1
|
+
export { e as AuthEndpoint, f as AuthMiddleware, v as callbackOAuth, T as changePassword, d as createAuthEndpoint, c as createAuthMiddleware, M as createEmailVerificationToken, $ as csrfMiddleware, V as deleteUser, Y as error, J as forgetPassword, K as forgetPasswordCallback, X as getCSRFToken, r as getEndpoints, w as getSession, x as getSessionFromCtx, z as listSessions, Z as ok, o as optionsMiddleware, L as resetPassword, C as revokeSession, D as revokeSessions, s as router, N as sendVerificationEmail, y as sessionMiddleware, U as setPassword, u as signInEmail, t as signInOAuth, E as signOut, _ as signUpEmail, Q as updateUser, O as verifyEmail } from './index-B5SM-JCa.js';
|
|
2
2
|
import './helper-DPDj8Nix.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
export { APIError } from 'better-call';
|
package/dist/api.js
CHANGED
|
@@ -1040,39 +1040,39 @@ var signInOAuth = createAuthEndpoint(
|
|
|
1040
1040
|
provider: z4.enum(oAuthProviderList)
|
|
1041
1041
|
})
|
|
1042
1042
|
},
|
|
1043
|
-
async (
|
|
1044
|
-
const provider =
|
|
1045
|
-
(p) => p.id ===
|
|
1043
|
+
async (c2) => {
|
|
1044
|
+
const provider = c2.context.socialProviders.find(
|
|
1045
|
+
(p) => p.id === c2.body.provider
|
|
1046
1046
|
);
|
|
1047
1047
|
if (!provider) {
|
|
1048
|
-
|
|
1048
|
+
c2.context.logger.error(
|
|
1049
1049
|
"Provider not found. Make sure to add the provider to your auth config",
|
|
1050
1050
|
{
|
|
1051
|
-
provider:
|
|
1051
|
+
provider: c2.body.provider
|
|
1052
1052
|
}
|
|
1053
1053
|
);
|
|
1054
1054
|
throw new APIError3("NOT_FOUND", {
|
|
1055
1055
|
message: "Provider not found"
|
|
1056
1056
|
});
|
|
1057
1057
|
}
|
|
1058
|
-
const cookie =
|
|
1059
|
-
const currentURL =
|
|
1060
|
-
const callbackURL =
|
|
1058
|
+
const cookie = c2.context.authCookies;
|
|
1059
|
+
const currentURL = c2.query?.currentURL ? new URL(c2.query?.currentURL) : null;
|
|
1060
|
+
const callbackURL = c2.body.callbackURL?.startsWith("http") ? c2.body.callbackURL : `${currentURL?.origin}${c2.body.callbackURL || ""}`;
|
|
1061
1061
|
const state = generateState(
|
|
1062
|
-
callbackURL || currentURL?.origin ||
|
|
1063
|
-
|
|
1062
|
+
callbackURL || currentURL?.origin || c2.context.baseURL,
|
|
1063
|
+
c2.query?.currentURL
|
|
1064
1064
|
);
|
|
1065
|
-
await
|
|
1065
|
+
await c2.setSignedCookie(
|
|
1066
1066
|
cookie.state.name,
|
|
1067
1067
|
state.code,
|
|
1068
|
-
|
|
1068
|
+
c2.context.secret,
|
|
1069
1069
|
cookie.state.options
|
|
1070
1070
|
);
|
|
1071
1071
|
const codeVerifier = generateCodeVerifier();
|
|
1072
|
-
await
|
|
1072
|
+
await c2.setSignedCookie(
|
|
1073
1073
|
cookie.pkCodeVerifier.name,
|
|
1074
1074
|
codeVerifier,
|
|
1075
|
-
|
|
1075
|
+
c2.context.secret,
|
|
1076
1076
|
cookie.pkCodeVerifier.options
|
|
1077
1077
|
);
|
|
1078
1078
|
const url = await provider.createAuthorizationURL({
|
|
@@ -1081,9 +1081,9 @@ var signInOAuth = createAuthEndpoint(
|
|
|
1081
1081
|
});
|
|
1082
1082
|
url.searchParams.set(
|
|
1083
1083
|
"redirect_uri",
|
|
1084
|
-
`${
|
|
1084
|
+
`${c2.context.baseURL}/callback/${c2.body.provider}`
|
|
1085
1085
|
);
|
|
1086
|
-
return
|
|
1086
|
+
return c2.json({
|
|
1087
1087
|
url: url.toString(),
|
|
1088
1088
|
state: state.state,
|
|
1089
1089
|
codeVerifier,
|
|
@@ -1128,7 +1128,9 @@ var signInEmail = createAuthEndpoint(
|
|
|
1128
1128
|
message: "Invalid email"
|
|
1129
1129
|
});
|
|
1130
1130
|
}
|
|
1131
|
-
const user = await ctx.context.internalAdapter.findUserByEmail(email
|
|
1131
|
+
const user = await ctx.context.internalAdapter.findUserByEmail(email, {
|
|
1132
|
+
includeAccounts: true
|
|
1133
|
+
});
|
|
1132
1134
|
if (!user) {
|
|
1133
1135
|
await ctx.context.password.hash(password);
|
|
1134
1136
|
ctx.context.logger.error("User not found", { email });
|
|
@@ -1182,6 +1184,17 @@ var signInEmail = createAuthEndpoint(
|
|
|
1182
1184
|
});
|
|
1183
1185
|
}
|
|
1184
1186
|
);
|
|
1187
|
+
var c = (o) => {
|
|
1188
|
+
};
|
|
1189
|
+
c({
|
|
1190
|
+
additional: {
|
|
1191
|
+
name: "string"
|
|
1192
|
+
},
|
|
1193
|
+
hooks: {
|
|
1194
|
+
create(user) {
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1185
1198
|
|
|
1186
1199
|
// src/api/routes/callback.ts
|
|
1187
1200
|
import { APIError as APIError4 } from "better-call";
|
|
@@ -1290,10 +1303,10 @@ function generateRandomInteger(max) {
|
|
|
1290
1303
|
}
|
|
1291
1304
|
return result;
|
|
1292
1305
|
}
|
|
1293
|
-
function generateRandomString(length,
|
|
1306
|
+
function generateRandomString(length, alphabet4) {
|
|
1294
1307
|
let result = "";
|
|
1295
1308
|
for (let i = 0; i < length; i++) {
|
|
1296
|
-
result +=
|
|
1309
|
+
result += alphabet4[generateRandomInteger(alphabet4.length)];
|
|
1297
1310
|
}
|
|
1298
1311
|
return result;
|
|
1299
1312
|
}
|
|
@@ -1352,63 +1365,63 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1352
1365
|
}),
|
|
1353
1366
|
metadata: HIDE_METADATA
|
|
1354
1367
|
},
|
|
1355
|
-
async (
|
|
1356
|
-
if (
|
|
1357
|
-
const parsedState2 = parseState(
|
|
1358
|
-
const callbackURL2 = parsedState2.data?.callbackURL || `${
|
|
1359
|
-
|
|
1360
|
-
throw
|
|
1361
|
-
`${callbackURL2}?error=${
|
|
1368
|
+
async (c2) => {
|
|
1369
|
+
if (c2.query.error || !c2.query.code) {
|
|
1370
|
+
const parsedState2 = parseState(c2.query.state);
|
|
1371
|
+
const callbackURL2 = parsedState2.data?.callbackURL || `${c2.context.baseURL}/error`;
|
|
1372
|
+
c2.context.logger.error(c2.query.error, c2.params.id);
|
|
1373
|
+
throw c2.redirect(
|
|
1374
|
+
`${callbackURL2}?error=${c2.query.error || "oAuth_code_missing"}`
|
|
1362
1375
|
);
|
|
1363
1376
|
}
|
|
1364
|
-
const provider =
|
|
1365
|
-
(p) => p.id ===
|
|
1377
|
+
const provider = c2.context.socialProviders.find(
|
|
1378
|
+
(p) => p.id === c2.params.id
|
|
1366
1379
|
);
|
|
1367
1380
|
if (!provider) {
|
|
1368
|
-
|
|
1381
|
+
c2.context.logger.error(
|
|
1369
1382
|
"Oauth provider with id",
|
|
1370
|
-
|
|
1383
|
+
c2.params.id,
|
|
1371
1384
|
"not found"
|
|
1372
1385
|
);
|
|
1373
|
-
throw
|
|
1374
|
-
`${
|
|
1386
|
+
throw c2.redirect(
|
|
1387
|
+
`${c2.context.baseURL}/error?error=oauth_provider_not_found`
|
|
1375
1388
|
);
|
|
1376
1389
|
}
|
|
1377
|
-
const parsedState = parseState(
|
|
1390
|
+
const parsedState = parseState(c2.query.state);
|
|
1378
1391
|
if (!parsedState.success) {
|
|
1379
|
-
|
|
1380
|
-
throw
|
|
1381
|
-
`${
|
|
1392
|
+
c2.context.logger.error("Unable to parse state");
|
|
1393
|
+
throw c2.redirect(
|
|
1394
|
+
`${c2.context.baseURL}/error?error=please_restart_the_process`
|
|
1382
1395
|
);
|
|
1383
1396
|
}
|
|
1384
1397
|
const {
|
|
1385
1398
|
data: { callbackURL, currentURL, code: stateCode }
|
|
1386
1399
|
} = parsedState;
|
|
1387
|
-
const storedState = await
|
|
1388
|
-
|
|
1389
|
-
|
|
1400
|
+
const storedState = await c2.getSignedCookie(
|
|
1401
|
+
c2.context.authCookies.state.name,
|
|
1402
|
+
c2.context.secret
|
|
1390
1403
|
);
|
|
1391
1404
|
if (storedState !== stateCode) {
|
|
1392
1405
|
logger.error("OAuth state mismatch", storedState, stateCode);
|
|
1393
|
-
throw
|
|
1394
|
-
`${
|
|
1406
|
+
throw c2.redirect(
|
|
1407
|
+
`${c2.context.baseURL}/error?error=please_restart_the_process`
|
|
1395
1408
|
);
|
|
1396
1409
|
}
|
|
1397
|
-
const codeVerifier = await
|
|
1398
|
-
|
|
1399
|
-
|
|
1410
|
+
const codeVerifier = await c2.getSignedCookie(
|
|
1411
|
+
c2.context.authCookies.pkCodeVerifier.name,
|
|
1412
|
+
c2.context.secret
|
|
1400
1413
|
);
|
|
1401
1414
|
let tokens;
|
|
1402
1415
|
try {
|
|
1403
1416
|
tokens = await provider.validateAuthorizationCode(
|
|
1404
|
-
|
|
1417
|
+
c2.query.code,
|
|
1405
1418
|
codeVerifier,
|
|
1406
|
-
`${
|
|
1419
|
+
`${c2.context.baseURL}/callback/${provider.id}`
|
|
1407
1420
|
);
|
|
1408
1421
|
} catch (e) {
|
|
1409
|
-
|
|
1410
|
-
throw
|
|
1411
|
-
`${
|
|
1422
|
+
c2.context.logger.error(e);
|
|
1423
|
+
throw c2.redirect(
|
|
1424
|
+
`${c2.context.baseURL}/error?error=please_restart_the_process`
|
|
1412
1425
|
);
|
|
1413
1426
|
}
|
|
1414
1427
|
const user = await provider.getUserInfo(tokens).then((res) => res?.user);
|
|
@@ -1419,22 +1432,24 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1419
1432
|
});
|
|
1420
1433
|
if (!user || data.success === false) {
|
|
1421
1434
|
logger.error("Unable to get user info", data.error);
|
|
1422
|
-
throw
|
|
1423
|
-
`${
|
|
1435
|
+
throw c2.redirect(
|
|
1436
|
+
`${c2.context.baseURL}/error?error=please_restart_the_process`
|
|
1424
1437
|
);
|
|
1425
1438
|
}
|
|
1426
1439
|
if (!callbackURL) {
|
|
1427
|
-
throw
|
|
1428
|
-
`${
|
|
1440
|
+
throw c2.redirect(
|
|
1441
|
+
`${c2.context.baseURL}/error?error=please_restart_the_process`
|
|
1429
1442
|
);
|
|
1430
1443
|
}
|
|
1431
|
-
const dbUser = await
|
|
1444
|
+
const dbUser = await c2.context.internalAdapter.findUserByEmail(user.email, {
|
|
1445
|
+
includeAccounts: true
|
|
1446
|
+
}).catch((e) => {
|
|
1432
1447
|
logger.error(
|
|
1433
1448
|
"Better auth was unable to query your database.\nError: ",
|
|
1434
1449
|
e
|
|
1435
1450
|
);
|
|
1436
|
-
throw
|
|
1437
|
-
`${
|
|
1451
|
+
throw c2.redirect(
|
|
1452
|
+
`${c2.context.baseURL}/error?error=internal_server_error`
|
|
1438
1453
|
);
|
|
1439
1454
|
});
|
|
1440
1455
|
const userId = dbUser?.user.id;
|
|
@@ -1442,7 +1457,7 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1442
1457
|
const hasBeenLinked = dbUser.accounts.find(
|
|
1443
1458
|
(a) => a.providerId === provider.id
|
|
1444
1459
|
);
|
|
1445
|
-
const trustedProviders =
|
|
1460
|
+
const trustedProviders = c2.context.options.account?.accountLinking?.trustedProviders;
|
|
1446
1461
|
const isTrustedProvider = trustedProviders ? trustedProviders.includes(provider.id) : true;
|
|
1447
1462
|
if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
|
|
1448
1463
|
let url;
|
|
@@ -1450,15 +1465,15 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1450
1465
|
url = new URL(currentURL || callbackURL);
|
|
1451
1466
|
url.searchParams.set("error", "account_not_linked");
|
|
1452
1467
|
} catch (e) {
|
|
1453
|
-
throw
|
|
1454
|
-
`${
|
|
1468
|
+
throw c2.redirect(
|
|
1469
|
+
`${c2.context.baseURL}/error?error=account_not_linked`
|
|
1455
1470
|
);
|
|
1456
1471
|
}
|
|
1457
|
-
throw
|
|
1472
|
+
throw c2.redirect(url.toString());
|
|
1458
1473
|
}
|
|
1459
1474
|
if (!hasBeenLinked) {
|
|
1460
1475
|
try {
|
|
1461
|
-
await
|
|
1476
|
+
await c2.context.internalAdapter.linkAccount({
|
|
1462
1477
|
providerId: provider.id,
|
|
1463
1478
|
accountId: user.id.toString(),
|
|
1464
1479
|
id: `${provider.id}:${user.id}`,
|
|
@@ -1467,14 +1482,14 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1467
1482
|
});
|
|
1468
1483
|
} catch (e) {
|
|
1469
1484
|
console.log(e);
|
|
1470
|
-
throw
|
|
1471
|
-
`${
|
|
1485
|
+
throw c2.redirect(
|
|
1486
|
+
`${c2.context.baseURL}/error?error=failed_linking_account`
|
|
1472
1487
|
);
|
|
1473
1488
|
}
|
|
1474
1489
|
}
|
|
1475
1490
|
} else {
|
|
1476
1491
|
try {
|
|
1477
|
-
await
|
|
1492
|
+
await c2.context.internalAdapter.createOAuthUser(data.data, {
|
|
1478
1493
|
...getAccountTokens(tokens),
|
|
1479
1494
|
id: `${provider.id}:${user.id}`,
|
|
1480
1495
|
providerId: provider.id,
|
|
@@ -1484,8 +1499,8 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1484
1499
|
} catch (e) {
|
|
1485
1500
|
const url = new URL(currentURL || callbackURL);
|
|
1486
1501
|
url.searchParams.set("error", "unable_to_create_user");
|
|
1487
|
-
|
|
1488
|
-
throw
|
|
1502
|
+
c2.setHeader("Location", url.toString());
|
|
1503
|
+
throw c2.redirect(url.toString());
|
|
1489
1504
|
}
|
|
1490
1505
|
}
|
|
1491
1506
|
if (!userId && !id)
|
|
@@ -1493,29 +1508,29 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1493
1508
|
message: "Unable to create user"
|
|
1494
1509
|
});
|
|
1495
1510
|
try {
|
|
1496
|
-
const session = await
|
|
1511
|
+
const session = await c2.context.internalAdapter.createSession(
|
|
1497
1512
|
userId || id,
|
|
1498
|
-
|
|
1513
|
+
c2.request
|
|
1499
1514
|
);
|
|
1500
1515
|
if (!session) {
|
|
1501
1516
|
const url = new URL(currentURL || callbackURL);
|
|
1502
1517
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1503
|
-
throw
|
|
1518
|
+
throw c2.redirect(url.toString());
|
|
1504
1519
|
}
|
|
1505
1520
|
try {
|
|
1506
|
-
await setSessionCookie(
|
|
1521
|
+
await setSessionCookie(c2, session.id);
|
|
1507
1522
|
} catch (e) {
|
|
1508
|
-
|
|
1523
|
+
c2.context.logger.error("Unable to set session cookie", e);
|
|
1509
1524
|
const url = new URL(currentURL || callbackURL);
|
|
1510
1525
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1511
|
-
throw
|
|
1526
|
+
throw c2.redirect(url.toString());
|
|
1512
1527
|
}
|
|
1513
1528
|
} catch {
|
|
1514
1529
|
const url = new URL(currentURL || callbackURL || "");
|
|
1515
1530
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1516
|
-
throw
|
|
1531
|
+
throw c2.redirect(url.toString());
|
|
1517
1532
|
}
|
|
1518
|
-
throw
|
|
1533
|
+
throw c2.redirect(callbackURL);
|
|
1519
1534
|
}
|
|
1520
1535
|
);
|
|
1521
1536
|
|
|
@@ -1587,7 +1602,9 @@ var forgetPassword = createAuthEndpoint(
|
|
|
1587
1602
|
});
|
|
1588
1603
|
}
|
|
1589
1604
|
const { email } = ctx.body;
|
|
1590
|
-
const user = await ctx.context.internalAdapter.findUserByEmail(email
|
|
1605
|
+
const user = await ctx.context.internalAdapter.findUserByEmail(email, {
|
|
1606
|
+
includeAccounts: true
|
|
1607
|
+
});
|
|
1591
1608
|
if (!user) {
|
|
1592
1609
|
ctx.context.logger.error("Reset Password: User not found", { email });
|
|
1593
1610
|
return ctx.json(
|
|
@@ -1787,11 +1804,17 @@ var sendVerificationEmail = createAuthEndpoint(
|
|
|
1787
1804
|
});
|
|
1788
1805
|
}
|
|
1789
1806
|
const { email } = ctx.body;
|
|
1807
|
+
const user = await ctx.context.internalAdapter.findUserByEmail(email);
|
|
1808
|
+
if (!user) {
|
|
1809
|
+
throw new APIError7("BAD_REQUEST", {
|
|
1810
|
+
message: "User not found"
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1790
1813
|
const token = await createEmailVerificationToken(ctx.context.secret, email);
|
|
1791
1814
|
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${ctx.body.callbackURL || ctx.query?.currentURL || "/"}`;
|
|
1792
1815
|
await ctx.context.options.emailAndPassword.sendVerificationEmail(
|
|
1793
|
-
email,
|
|
1794
1816
|
url,
|
|
1817
|
+
user.user,
|
|
1795
1818
|
token
|
|
1796
1819
|
);
|
|
1797
1820
|
return ctx.json({
|
|
@@ -1815,12 +1838,8 @@ var verifyEmail = createAuthEndpoint(
|
|
|
1815
1838
|
jwt = await validateJWT2("HS256", Buffer.from(ctx.context.secret), token);
|
|
1816
1839
|
} catch (e) {
|
|
1817
1840
|
ctx.context.logger.error("Failed to verify email", e);
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
statusText: "INVALID_TOKEN",
|
|
1821
|
-
body: {
|
|
1822
|
-
message: "Invalid token"
|
|
1823
|
-
}
|
|
1841
|
+
throw new APIError7("BAD_REQUEST", {
|
|
1842
|
+
message: "Invalid token"
|
|
1824
1843
|
});
|
|
1825
1844
|
}
|
|
1826
1845
|
const schema = z9.object({
|
|
@@ -1828,20 +1847,19 @@ var verifyEmail = createAuthEndpoint(
|
|
|
1828
1847
|
});
|
|
1829
1848
|
const parsed = schema.parse(jwt.payload);
|
|
1830
1849
|
const user = await ctx.context.internalAdapter.findUserByEmail(
|
|
1831
|
-
parsed.email
|
|
1850
|
+
parsed.email,
|
|
1851
|
+
{ includeAccounts: true }
|
|
1832
1852
|
);
|
|
1833
1853
|
if (!user) {
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
statusText: "USER_NOT_FOUND",
|
|
1837
|
-
body: {
|
|
1838
|
-
message: "User not found"
|
|
1839
|
-
}
|
|
1854
|
+
throw new APIError7("BAD_REQUEST", {
|
|
1855
|
+
message: "User not found"
|
|
1840
1856
|
});
|
|
1841
1857
|
}
|
|
1842
1858
|
const account = user.accounts.find((a) => a.providerId === "credential");
|
|
1843
1859
|
if (!account) {
|
|
1844
|
-
throw
|
|
1860
|
+
throw new APIError7("BAD_REQUEST", {
|
|
1861
|
+
message: "Account not found"
|
|
1862
|
+
});
|
|
1845
1863
|
}
|
|
1846
1864
|
await ctx.context.internalAdapter.updateUserByEmail(parsed.email, {
|
|
1847
1865
|
emailVerified: true
|
|
@@ -2175,8 +2193,8 @@ var error = createAuthEndpoint(
|
|
|
2175
2193
|
method: "GET",
|
|
2176
2194
|
metadata: HIDE_METADATA
|
|
2177
2195
|
},
|
|
2178
|
-
async (
|
|
2179
|
-
const query = new URL(
|
|
2196
|
+
async (c2) => {
|
|
2197
|
+
const query = new URL(c2.request?.url || "").searchParams.get("error") || "Unknown";
|
|
2180
2198
|
return new Response(html(query), {
|
|
2181
2199
|
headers: {
|
|
2182
2200
|
"Content-Type": "text/html"
|
|
@@ -2264,11 +2282,11 @@ var signUpEmail = () => createAuthEndpoint(
|
|
|
2264
2282
|
}
|
|
2265
2283
|
const hash = await ctx.context.password.hash(password);
|
|
2266
2284
|
await ctx.context.internalAdapter.linkAccount({
|
|
2267
|
-
id: generateRandomString(32, alphabet("a-z", "0-9", "A-Z")),
|
|
2268
2285
|
userId: createdUser.id,
|
|
2269
2286
|
providerId: "credential",
|
|
2270
2287
|
accountId: createdUser.id,
|
|
2271
|
-
password: hash
|
|
2288
|
+
password: hash,
|
|
2289
|
+
expiresAt: getDate(60 * 60 * 24 * 30, "sec")
|
|
2272
2290
|
});
|
|
2273
2291
|
const session = await ctx.context.internalAdapter.createSession(
|
|
2274
2292
|
createdUser.id,
|
|
@@ -2287,8 +2305,8 @@ var signUpEmail = () => createAuthEndpoint(
|
|
|
2287
2305
|
);
|
|
2288
2306
|
const url = `${ctx.context.baseURL}/verify-email?token=${token}&callbackURL=${body.callbackURL || ctx.query?.currentURL || "/"}`;
|
|
2289
2307
|
await ctx.context.options.emailAndPassword.sendVerificationEmail?.(
|
|
2290
|
-
createdUser.email,
|
|
2291
2308
|
url,
|
|
2309
|
+
createdUser,
|
|
2292
2310
|
token
|
|
2293
2311
|
);
|
|
2294
2312
|
}
|
|
@@ -2569,26 +2587,26 @@ function getEndpoints(ctx, options) {
|
|
|
2569
2587
|
let api = {};
|
|
2570
2588
|
for (const [key, value] of Object.entries(endpoints)) {
|
|
2571
2589
|
api[key] = async (context) => {
|
|
2572
|
-
let
|
|
2590
|
+
let c2 = await ctx;
|
|
2573
2591
|
for (const plugin of options.plugins || []) {
|
|
2574
2592
|
if (plugin.hooks?.before) {
|
|
2575
2593
|
for (const hook of plugin.hooks.before) {
|
|
2576
2594
|
const match = hook.matcher({
|
|
2577
2595
|
...value,
|
|
2578
2596
|
...context,
|
|
2579
|
-
context:
|
|
2597
|
+
context: c2
|
|
2580
2598
|
});
|
|
2581
2599
|
if (match) {
|
|
2582
2600
|
const hookRes = await hook.handler({
|
|
2583
2601
|
...context,
|
|
2584
2602
|
context: {
|
|
2585
|
-
...
|
|
2603
|
+
...c2,
|
|
2586
2604
|
...context.context
|
|
2587
2605
|
}
|
|
2588
2606
|
});
|
|
2589
2607
|
if (hookRes && "context" in hookRes) {
|
|
2590
|
-
|
|
2591
|
-
...
|
|
2608
|
+
c2 = {
|
|
2609
|
+
...c2,
|
|
2592
2610
|
...hookRes.context
|
|
2593
2611
|
};
|
|
2594
2612
|
}
|
|
@@ -2599,7 +2617,7 @@ function getEndpoints(ctx, options) {
|
|
|
2599
2617
|
const endpointRes = await value({
|
|
2600
2618
|
...context,
|
|
2601
2619
|
context: {
|
|
2602
|
-
...
|
|
2620
|
+
...c2,
|
|
2603
2621
|
...context.context
|
|
2604
2622
|
}
|
|
2605
2623
|
});
|
package/dist/client/plugins.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as nanostores from 'nanostores';
|
|
|
2
2
|
import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CfnyN34h.js';
|
|
3
3
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
4
4
|
import { BetterFetchOption } from '@better-fetch/fetch';
|
|
5
|
-
import { o as organization, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, j as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin } from '../index-45sX2yHG.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-45sX2yHG.js';
|
|
7
7
|
import { P as Prettify } from '../helper-DPDj8Nix.js';
|
|
8
|
-
import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-
|
|
8
|
+
import { F as FieldAttribute, B as BetterAuthOptions, b as BetterAuthPlugin } from '../index-B5SM-JCa.js';
|
|
9
9
|
import * as better_call from 'better-call';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import { O as OAuth2Tokens, U as User } from '../types-IzAbV4nB.js';
|
package/dist/client.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/
|
|
|
6
6
|
import { U as UnionToIntersection, P as Prettify, S as StripEmptyObjects } from './helper-DPDj8Nix.js';
|
|
7
7
|
import { ClientOptions, InferClientAPI, InferActions, InferAdditionalFromClient, InferSessionFromClient, InferUserFromClient, BetterAuthClientPlugin, IsSignal } from './types.js';
|
|
8
8
|
export { AtomListener, InferPluginsFromClient } from './types.js';
|
|
9
|
-
import './index-
|
|
9
|
+
import './index-B5SM-JCa.js';
|
|
10
10
|
import 'kysely';
|
|
11
11
|
import './types-IzAbV4nB.js';
|
|
12
12
|
import 'better-call';
|
|
@@ -5,7 +5,7 @@ import { P as Prettify } from './helper-DPDj8Nix.js';
|
|
|
5
5
|
import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CfnyN34h.js';
|
|
6
6
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
7
7
|
import { BetterFetch, BetterFetchOption } from '@better-fetch/fetch';
|
|
8
|
-
import { H as HookEndpointContext, g as AuthContext } from './index-
|
|
8
|
+
import { H as HookEndpointContext, g as AuthContext } from './index-B5SM-JCa.js';
|
|
9
9
|
import * as nanostores from 'nanostores';
|
|
10
10
|
import { atom } from 'nanostores';
|
|
11
11
|
import * as _simplewebauthn_types from '@simplewebauthn/types';
|
|
@@ -4777,11 +4777,61 @@ declare const adminMiddleware: better_call.Endpoint<better_call.Handler<string,
|
|
|
4777
4777
|
};
|
|
4778
4778
|
};
|
|
4779
4779
|
}>, better_call.EndpointOptions>;
|
|
4780
|
-
|
|
4780
|
+
interface AdminOptions {
|
|
4781
|
+
/**
|
|
4782
|
+
* The default role for a user created by the admin
|
|
4783
|
+
*
|
|
4784
|
+
* @default "user"
|
|
4785
|
+
*/
|
|
4786
|
+
defaultRole?: string | false;
|
|
4787
|
+
/**
|
|
4788
|
+
* A default ban reason
|
|
4789
|
+
*
|
|
4790
|
+
* By default, no reason is provided
|
|
4791
|
+
*/
|
|
4792
|
+
defaultBanReason?: string;
|
|
4793
|
+
/**
|
|
4794
|
+
* Number of seconds until the ban expires
|
|
4795
|
+
*
|
|
4796
|
+
* By default, the ban never expires
|
|
4797
|
+
*/
|
|
4798
|
+
defaultBanExpiresIn?: number;
|
|
4799
|
+
/**
|
|
4800
|
+
* Duration of the impersonation session in seconds
|
|
4801
|
+
*
|
|
4802
|
+
* By default, the impersonation session lasts 1 hour
|
|
4803
|
+
*/
|
|
4804
|
+
impersonationSessionDuration?: number;
|
|
4805
|
+
}
|
|
4806
|
+
declare const admin: (options?: AdminOptions) => {
|
|
4781
4807
|
id: "admin";
|
|
4782
4808
|
init(ctx: AuthContext): {
|
|
4783
4809
|
options: {
|
|
4784
4810
|
databaseHooks: {
|
|
4811
|
+
user: {
|
|
4812
|
+
create: {
|
|
4813
|
+
before(user: {
|
|
4814
|
+
id: string;
|
|
4815
|
+
email: string;
|
|
4816
|
+
emailVerified: boolean;
|
|
4817
|
+
name: string;
|
|
4818
|
+
createdAt: Date;
|
|
4819
|
+
updatedAt: Date;
|
|
4820
|
+
image?: string | undefined;
|
|
4821
|
+
}): Promise<{
|
|
4822
|
+
data: {
|
|
4823
|
+
id: string;
|
|
4824
|
+
email: string;
|
|
4825
|
+
emailVerified: boolean;
|
|
4826
|
+
name: string;
|
|
4827
|
+
createdAt: Date;
|
|
4828
|
+
updatedAt: Date;
|
|
4829
|
+
image?: string | undefined;
|
|
4830
|
+
role: string;
|
|
4831
|
+
};
|
|
4832
|
+
} | undefined>;
|
|
4833
|
+
};
|
|
4834
|
+
};
|
|
4785
4835
|
session: {
|
|
4786
4836
|
create: {
|
|
4787
4837
|
before(session: {
|