better-auth 0.4.9-beta.5 → 0.4.9-beta.7
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 +89 -125
- package/dist/client/plugins.d.ts +3 -3
- package/dist/client.d.ts +1 -1
- package/dist/client.js +3 -7
- package/dist/{index-xf537-bb.d.ts → index-DLbRYrL5.d.ts} +37 -92
- package/dist/{index-x0qUJonH.d.ts → index-e3_mbU9X.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +96 -132
- 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 +94 -130
- package/dist/react.d.ts +1 -1
- package/dist/react.js +3 -7
- package/dist/solid-start.d.ts +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/solid.js +3 -7
- package/dist/svelte-kit.d.ts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +3 -7
- package/dist/types.d.ts +2 -2
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +3 -7
- 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-DLbRYrL5.js';
|
|
2
2
|
import './helper-DPDj8Nix.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
export { APIError } from 'better-call';
|
package/dist/api.js
CHANGED
|
@@ -67,7 +67,7 @@ var csrfMiddleware = createAuthMiddleware(
|
|
|
67
67
|
if (ctx.context.trustedOrigins.includes(url.origin)) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
const csrfToken = ctx.
|
|
70
|
+
const csrfToken = ctx.body?.csrfToken;
|
|
71
71
|
if (!csrfToken) {
|
|
72
72
|
throw new APIError2("UNAUTHORIZED", {
|
|
73
73
|
message: "CSRF Token is required"
|
|
@@ -1026,8 +1026,9 @@ var redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
|
|
|
1026
1026
|
if (callbackURL?.includes("http")) {
|
|
1027
1027
|
const callbackOrigin = new URL(callbackURL).origin;
|
|
1028
1028
|
if (!trustedOrigins.includes(callbackOrigin)) {
|
|
1029
|
-
logger.error("
|
|
1030
|
-
callbackURL
|
|
1029
|
+
logger.error("Invalid callback URL", {
|
|
1030
|
+
callbackURL,
|
|
1031
|
+
trustedOrigins
|
|
1031
1032
|
});
|
|
1032
1033
|
throw new APIError4("FORBIDDEN", {
|
|
1033
1034
|
message: "Invalid callback URL"
|
|
@@ -1037,7 +1038,7 @@ var redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
|
|
|
1037
1038
|
if (currentURL !== ctx.context.baseURL) {
|
|
1038
1039
|
const currentURLOrigin = new URL(currentURL).origin;
|
|
1039
1040
|
if (!trustedOrigins.includes(currentURLOrigin)) {
|
|
1040
|
-
logger.error("
|
|
1041
|
+
logger.error("Invalid current URL", {
|
|
1041
1042
|
currentURL,
|
|
1042
1043
|
trustedOrigins
|
|
1043
1044
|
});
|
|
@@ -1046,7 +1047,6 @@ var redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
|
|
|
1046
1047
|
});
|
|
1047
1048
|
}
|
|
1048
1049
|
}
|
|
1049
|
-
ctx.setHeader("x-auth-redirect", "true");
|
|
1050
1050
|
});
|
|
1051
1051
|
|
|
1052
1052
|
// src/api/routes/sign-in.ts
|
|
@@ -1074,39 +1074,39 @@ var signInOAuth = createAuthEndpoint(
|
|
|
1074
1074
|
}),
|
|
1075
1075
|
use: [redirectURLMiddleware]
|
|
1076
1076
|
},
|
|
1077
|
-
async (
|
|
1078
|
-
const provider =
|
|
1079
|
-
(p) => p.id ===
|
|
1077
|
+
async (c) => {
|
|
1078
|
+
const provider = c.context.socialProviders.find(
|
|
1079
|
+
(p) => p.id === c.body.provider
|
|
1080
1080
|
);
|
|
1081
1081
|
if (!provider) {
|
|
1082
|
-
|
|
1082
|
+
c.context.logger.error(
|
|
1083
1083
|
"Provider not found. Make sure to add the provider to your auth config",
|
|
1084
1084
|
{
|
|
1085
|
-
provider:
|
|
1085
|
+
provider: c.body.provider
|
|
1086
1086
|
}
|
|
1087
1087
|
);
|
|
1088
1088
|
throw new APIError5("NOT_FOUND", {
|
|
1089
1089
|
message: "Provider not found"
|
|
1090
1090
|
});
|
|
1091
1091
|
}
|
|
1092
|
-
const cookie =
|
|
1093
|
-
const currentURL =
|
|
1094
|
-
const callbackURL =
|
|
1092
|
+
const cookie = c.context.authCookies;
|
|
1093
|
+
const currentURL = c.query?.currentURL ? new URL(c.query?.currentURL) : null;
|
|
1094
|
+
const callbackURL = c.body.callbackURL?.startsWith("http") ? c.body.callbackURL : `${currentURL?.origin}${c.body.callbackURL || ""}`;
|
|
1095
1095
|
const state = generateState(
|
|
1096
|
-
callbackURL || currentURL?.origin ||
|
|
1097
|
-
|
|
1096
|
+
callbackURL || currentURL?.origin || c.context.baseURL,
|
|
1097
|
+
c.query?.currentURL
|
|
1098
1098
|
);
|
|
1099
|
-
await
|
|
1099
|
+
await c.setSignedCookie(
|
|
1100
1100
|
cookie.state.name,
|
|
1101
1101
|
state,
|
|
1102
|
-
|
|
1102
|
+
c.context.secret,
|
|
1103
1103
|
cookie.state.options
|
|
1104
1104
|
);
|
|
1105
1105
|
const codeVerifier = generateCodeVerifier();
|
|
1106
|
-
await
|
|
1106
|
+
await c.setSignedCookie(
|
|
1107
1107
|
cookie.pkCodeVerifier.name,
|
|
1108
1108
|
codeVerifier,
|
|
1109
|
-
|
|
1109
|
+
c.context.secret,
|
|
1110
1110
|
cookie.pkCodeVerifier.options
|
|
1111
1111
|
);
|
|
1112
1112
|
const url = await provider.createAuthorizationURL({
|
|
@@ -1115,9 +1115,9 @@ var signInOAuth = createAuthEndpoint(
|
|
|
1115
1115
|
});
|
|
1116
1116
|
url.searchParams.set(
|
|
1117
1117
|
"redirect_uri",
|
|
1118
|
-
`${
|
|
1118
|
+
`${c.context.baseURL}/callback/${c.body.provider}`
|
|
1119
1119
|
);
|
|
1120
|
-
return
|
|
1120
|
+
return c.json({
|
|
1121
1121
|
url: url.toString(),
|
|
1122
1122
|
state,
|
|
1123
1123
|
codeVerifier,
|
|
@@ -1150,12 +1150,6 @@ var signInEmail = createAuthEndpoint(
|
|
|
1150
1150
|
message: "Email and password is not enabled"
|
|
1151
1151
|
});
|
|
1152
1152
|
}
|
|
1153
|
-
const currentSession = await getSessionFromCtx(ctx);
|
|
1154
|
-
if (currentSession) {
|
|
1155
|
-
await ctx.context.internalAdapter.deleteSession(
|
|
1156
|
-
currentSession.session.id
|
|
1157
|
-
);
|
|
1158
|
-
}
|
|
1159
1153
|
const { email, password } = ctx.body;
|
|
1160
1154
|
const checkEmail = z4.string().email().safeParse(email);
|
|
1161
1155
|
if (!checkEmail.success) {
|
|
@@ -1219,17 +1213,6 @@ var signInEmail = createAuthEndpoint(
|
|
|
1219
1213
|
});
|
|
1220
1214
|
}
|
|
1221
1215
|
);
|
|
1222
|
-
var c = (o) => {
|
|
1223
|
-
};
|
|
1224
|
-
c({
|
|
1225
|
-
additional: {
|
|
1226
|
-
name: "string"
|
|
1227
|
-
},
|
|
1228
|
-
hooks: {
|
|
1229
|
-
create(user) {
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
});
|
|
1233
1216
|
|
|
1234
1217
|
// src/api/routes/callback.ts
|
|
1235
1218
|
import { APIError as APIError6 } from "better-call";
|
|
@@ -1400,63 +1383,63 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1400
1383
|
}),
|
|
1401
1384
|
metadata: HIDE_METADATA
|
|
1402
1385
|
},
|
|
1403
|
-
async (
|
|
1404
|
-
if (
|
|
1405
|
-
const parsedState2 = parseState(
|
|
1406
|
-
const callbackURL2 = parsedState2.data?.callbackURL || `${
|
|
1407
|
-
|
|
1408
|
-
throw
|
|
1409
|
-
`${callbackURL2}?error=${
|
|
1386
|
+
async (c) => {
|
|
1387
|
+
if (c.query.error || !c.query.code) {
|
|
1388
|
+
const parsedState2 = parseState(c.query.state);
|
|
1389
|
+
const callbackURL2 = parsedState2.data?.callbackURL || `${c.context.baseURL}/error`;
|
|
1390
|
+
c.context.logger.error(c.query.error, c.params.id);
|
|
1391
|
+
throw c.redirect(
|
|
1392
|
+
`${callbackURL2}?error=${c.query.error || "oAuth_code_missing"}`
|
|
1410
1393
|
);
|
|
1411
1394
|
}
|
|
1412
|
-
const provider =
|
|
1413
|
-
(p) => p.id ===
|
|
1395
|
+
const provider = c.context.socialProviders.find(
|
|
1396
|
+
(p) => p.id === c.params.id
|
|
1414
1397
|
);
|
|
1415
1398
|
if (!provider) {
|
|
1416
|
-
|
|
1399
|
+
c.context.logger.error(
|
|
1417
1400
|
"Oauth provider with id",
|
|
1418
|
-
|
|
1401
|
+
c.params.id,
|
|
1419
1402
|
"not found"
|
|
1420
1403
|
);
|
|
1421
|
-
throw
|
|
1422
|
-
`${
|
|
1404
|
+
throw c.redirect(
|
|
1405
|
+
`${c.context.baseURL}/error?error=oauth_provider_not_found`
|
|
1423
1406
|
);
|
|
1424
1407
|
}
|
|
1425
|
-
const parsedState = parseState(
|
|
1408
|
+
const parsedState = parseState(c.query.state);
|
|
1426
1409
|
if (!parsedState.success) {
|
|
1427
|
-
|
|
1428
|
-
throw
|
|
1429
|
-
`${
|
|
1410
|
+
c.context.logger.error("Unable to parse state");
|
|
1411
|
+
throw c.redirect(
|
|
1412
|
+
`${c.context.baseURL}/error?error=please_restart_the_process`
|
|
1430
1413
|
);
|
|
1431
1414
|
}
|
|
1432
1415
|
const {
|
|
1433
1416
|
data: { callbackURL, currentURL }
|
|
1434
1417
|
} = parsedState;
|
|
1435
|
-
const storedState = await
|
|
1436
|
-
|
|
1437
|
-
|
|
1418
|
+
const storedState = await c.getSignedCookie(
|
|
1419
|
+
c.context.authCookies.state.name,
|
|
1420
|
+
c.context.secret
|
|
1438
1421
|
);
|
|
1439
|
-
if (storedState !==
|
|
1422
|
+
if (storedState !== c.query.state) {
|
|
1440
1423
|
logger.error("OAuth state mismatch");
|
|
1441
|
-
throw
|
|
1442
|
-
`${
|
|
1424
|
+
throw c.redirect(
|
|
1425
|
+
`${c.context.baseURL}/error?error=please_restart_the_process`
|
|
1443
1426
|
);
|
|
1444
1427
|
}
|
|
1445
|
-
const codeVerifier = await
|
|
1446
|
-
|
|
1447
|
-
|
|
1428
|
+
const codeVerifier = await c.getSignedCookie(
|
|
1429
|
+
c.context.authCookies.pkCodeVerifier.name,
|
|
1430
|
+
c.context.secret
|
|
1448
1431
|
);
|
|
1449
1432
|
let tokens;
|
|
1450
1433
|
try {
|
|
1451
1434
|
tokens = await provider.validateAuthorizationCode(
|
|
1452
|
-
|
|
1435
|
+
c.query.code,
|
|
1453
1436
|
codeVerifier,
|
|
1454
|
-
`${
|
|
1437
|
+
`${c.context.baseURL}/callback/${provider.id}`
|
|
1455
1438
|
);
|
|
1456
1439
|
} catch (e) {
|
|
1457
|
-
|
|
1458
|
-
throw
|
|
1459
|
-
`${
|
|
1440
|
+
c.context.logger.error(e);
|
|
1441
|
+
throw c.redirect(
|
|
1442
|
+
`${c.context.baseURL}/error?error=please_restart_the_process`
|
|
1460
1443
|
);
|
|
1461
1444
|
}
|
|
1462
1445
|
const user = await provider.getUserInfo(tokens).then((res) => res?.user);
|
|
@@ -1467,24 +1450,24 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1467
1450
|
});
|
|
1468
1451
|
if (!user || data.success === false) {
|
|
1469
1452
|
logger.error("Unable to get user info", data.error);
|
|
1470
|
-
throw
|
|
1471
|
-
`${
|
|
1453
|
+
throw c.redirect(
|
|
1454
|
+
`${c.context.baseURL}/error?error=please_restart_the_process`
|
|
1472
1455
|
);
|
|
1473
1456
|
}
|
|
1474
1457
|
if (!callbackURL) {
|
|
1475
|
-
throw
|
|
1476
|
-
`${
|
|
1458
|
+
throw c.redirect(
|
|
1459
|
+
`${c.context.baseURL}/error?error=please_restart_the_process`
|
|
1477
1460
|
);
|
|
1478
1461
|
}
|
|
1479
|
-
const dbUser = await
|
|
1462
|
+
const dbUser = await c.context.internalAdapter.findUserByEmail(user.email, {
|
|
1480
1463
|
includeAccounts: true
|
|
1481
1464
|
}).catch((e) => {
|
|
1482
1465
|
logger.error(
|
|
1483
1466
|
"Better auth was unable to query your database.\nError: ",
|
|
1484
1467
|
e
|
|
1485
1468
|
);
|
|
1486
|
-
throw
|
|
1487
|
-
`${
|
|
1469
|
+
throw c.redirect(
|
|
1470
|
+
`${c.context.baseURL}/error?error=internal_server_error`
|
|
1488
1471
|
);
|
|
1489
1472
|
});
|
|
1490
1473
|
const userId = dbUser?.user.id;
|
|
@@ -1492,7 +1475,7 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1492
1475
|
const hasBeenLinked = dbUser.accounts.find(
|
|
1493
1476
|
(a) => a.providerId === provider.id
|
|
1494
1477
|
);
|
|
1495
|
-
const trustedProviders =
|
|
1478
|
+
const trustedProviders = c.context.options.account?.accountLinking?.trustedProviders;
|
|
1496
1479
|
const isTrustedProvider = trustedProviders ? trustedProviders.includes(provider.id) : true;
|
|
1497
1480
|
if (!hasBeenLinked && (!user.emailVerified || !isTrustedProvider)) {
|
|
1498
1481
|
let url;
|
|
@@ -1500,15 +1483,15 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1500
1483
|
url = new URL(currentURL || callbackURL);
|
|
1501
1484
|
url.searchParams.set("error", "account_not_linked");
|
|
1502
1485
|
} catch (e) {
|
|
1503
|
-
throw
|
|
1504
|
-
`${
|
|
1486
|
+
throw c.redirect(
|
|
1487
|
+
`${c.context.baseURL}/error?error=account_not_linked`
|
|
1505
1488
|
);
|
|
1506
1489
|
}
|
|
1507
|
-
throw
|
|
1490
|
+
throw c.redirect(url.toString());
|
|
1508
1491
|
}
|
|
1509
1492
|
if (!hasBeenLinked) {
|
|
1510
1493
|
try {
|
|
1511
|
-
await
|
|
1494
|
+
await c.context.internalAdapter.linkAccount({
|
|
1512
1495
|
providerId: provider.id,
|
|
1513
1496
|
accountId: user.id.toString(),
|
|
1514
1497
|
id: `${provider.id}:${user.id}`,
|
|
@@ -1517,14 +1500,14 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1517
1500
|
});
|
|
1518
1501
|
} catch (e) {
|
|
1519
1502
|
console.log(e);
|
|
1520
|
-
throw
|
|
1521
|
-
`${
|
|
1503
|
+
throw c.redirect(
|
|
1504
|
+
`${c.context.baseURL}/error?error=failed_linking_account`
|
|
1522
1505
|
);
|
|
1523
1506
|
}
|
|
1524
1507
|
}
|
|
1525
1508
|
} else {
|
|
1526
1509
|
try {
|
|
1527
|
-
await
|
|
1510
|
+
await c.context.internalAdapter.createOAuthUser(data.data, {
|
|
1528
1511
|
...getAccountTokens(tokens),
|
|
1529
1512
|
id: `${provider.id}:${user.id}`,
|
|
1530
1513
|
providerId: provider.id,
|
|
@@ -1534,8 +1517,8 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1534
1517
|
} catch (e) {
|
|
1535
1518
|
const url = new URL(currentURL || callbackURL);
|
|
1536
1519
|
url.searchParams.set("error", "unable_to_create_user");
|
|
1537
|
-
|
|
1538
|
-
throw
|
|
1520
|
+
c.setHeader("Location", url.toString());
|
|
1521
|
+
throw c.redirect(url.toString());
|
|
1539
1522
|
}
|
|
1540
1523
|
}
|
|
1541
1524
|
if (!userId && !id)
|
|
@@ -1543,57 +1526,41 @@ var callbackOAuth = createAuthEndpoint(
|
|
|
1543
1526
|
message: "Unable to create user"
|
|
1544
1527
|
});
|
|
1545
1528
|
try {
|
|
1546
|
-
const session = await
|
|
1529
|
+
const session = await c.context.internalAdapter.createSession(
|
|
1547
1530
|
userId || id,
|
|
1548
|
-
|
|
1531
|
+
c.request
|
|
1549
1532
|
);
|
|
1550
1533
|
if (!session) {
|
|
1551
1534
|
const url = new URL(currentURL || callbackURL);
|
|
1552
1535
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1553
|
-
throw
|
|
1536
|
+
throw c.redirect(url.toString());
|
|
1554
1537
|
}
|
|
1555
1538
|
try {
|
|
1556
|
-
await setSessionCookie(
|
|
1539
|
+
await setSessionCookie(c, session.id);
|
|
1557
1540
|
} catch (e) {
|
|
1558
|
-
|
|
1541
|
+
c.context.logger.error("Unable to set session cookie", e);
|
|
1559
1542
|
const url = new URL(currentURL || callbackURL);
|
|
1560
1543
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1561
|
-
throw
|
|
1544
|
+
throw c.redirect(url.toString());
|
|
1562
1545
|
}
|
|
1563
1546
|
} catch {
|
|
1564
1547
|
const url = new URL(currentURL || callbackURL || "");
|
|
1565
1548
|
url.searchParams.set("error", "unable_to_create_session");
|
|
1566
|
-
throw
|
|
1549
|
+
throw c.redirect(url.toString());
|
|
1567
1550
|
}
|
|
1568
|
-
throw
|
|
1551
|
+
throw c.redirect(callbackURL);
|
|
1569
1552
|
}
|
|
1570
1553
|
);
|
|
1571
1554
|
|
|
1572
1555
|
// src/api/routes/sign-out.ts
|
|
1573
|
-
import
|
|
1556
|
+
import "zod";
|
|
1574
1557
|
import { APIError as APIError7 } from "better-call";
|
|
1575
1558
|
var signOut = createAuthEndpoint(
|
|
1576
1559
|
"/sign-out",
|
|
1577
1560
|
{
|
|
1578
|
-
method: "POST"
|
|
1579
|
-
body: z7.optional(
|
|
1580
|
-
z7.object({
|
|
1581
|
-
callbackURL: z7.string().optional()
|
|
1582
|
-
})
|
|
1583
|
-
),
|
|
1584
|
-
use: [redirectURLMiddleware]
|
|
1561
|
+
method: "POST"
|
|
1585
1562
|
},
|
|
1586
1563
|
async (ctx) => {
|
|
1587
|
-
const callbackOrigin = ctx.body?.callbackURL ? new URL(ctx.body.callbackURL).origin : null;
|
|
1588
|
-
const trustedOrigins = [
|
|
1589
|
-
ctx.context.baseURL,
|
|
1590
|
-
...ctx.context.options.trustedOrigins || []
|
|
1591
|
-
];
|
|
1592
|
-
if (callbackOrigin && !trustedOrigins.includes(callbackOrigin)) {
|
|
1593
|
-
throw new APIError7("UNAUTHORIZED", {
|
|
1594
|
-
message: "Invalid callback URL"
|
|
1595
|
-
});
|
|
1596
|
-
}
|
|
1597
1564
|
const sessionCookieToken = await ctx.getSignedCookie(
|
|
1598
1565
|
ctx.context.authCookies.sessionToken.name,
|
|
1599
1566
|
ctx.context.secret
|
|
@@ -1605,11 +1572,8 @@ var signOut = createAuthEndpoint(
|
|
|
1605
1572
|
}
|
|
1606
1573
|
await ctx.context.internalAdapter.deleteSession(sessionCookieToken);
|
|
1607
1574
|
deleteSessionCookie(ctx);
|
|
1608
|
-
return ctx.json(
|
|
1609
|
-
|
|
1610
|
-
redirect: !!ctx.body?.callbackURL,
|
|
1611
|
-
url: ctx.body?.callbackURL
|
|
1612
|
-
}
|
|
1575
|
+
return ctx.json({
|
|
1576
|
+
success: true
|
|
1613
1577
|
});
|
|
1614
1578
|
}
|
|
1615
1579
|
);
|
|
@@ -2241,8 +2205,8 @@ var error = createAuthEndpoint(
|
|
|
2241
2205
|
method: "GET",
|
|
2242
2206
|
metadata: HIDE_METADATA
|
|
2243
2207
|
},
|
|
2244
|
-
async (
|
|
2245
|
-
const query = new URL(
|
|
2208
|
+
async (c) => {
|
|
2209
|
+
const query = new URL(c.request?.url || "").searchParams.get("error") || "Unknown";
|
|
2246
2210
|
return new Response(html(query), {
|
|
2247
2211
|
headers: {
|
|
2248
2212
|
"Content-Type": "text/html"
|
|
@@ -2636,26 +2600,26 @@ function getEndpoints(ctx, options) {
|
|
|
2636
2600
|
let api = {};
|
|
2637
2601
|
for (const [key, value] of Object.entries(endpoints)) {
|
|
2638
2602
|
api[key] = async (context) => {
|
|
2639
|
-
let
|
|
2603
|
+
let c = await ctx;
|
|
2640
2604
|
for (const plugin of options.plugins || []) {
|
|
2641
2605
|
if (plugin.hooks?.before) {
|
|
2642
2606
|
for (const hook of plugin.hooks.before) {
|
|
2643
2607
|
const match = hook.matcher({
|
|
2644
2608
|
...value,
|
|
2645
2609
|
...context,
|
|
2646
|
-
context:
|
|
2610
|
+
context: c
|
|
2647
2611
|
});
|
|
2648
2612
|
if (match) {
|
|
2649
2613
|
const hookRes = await hook.handler({
|
|
2650
2614
|
...context,
|
|
2651
2615
|
context: {
|
|
2652
|
-
...
|
|
2616
|
+
...c,
|
|
2653
2617
|
...context.context
|
|
2654
2618
|
}
|
|
2655
2619
|
});
|
|
2656
2620
|
if (hookRes && "context" in hookRes) {
|
|
2657
|
-
|
|
2658
|
-
...
|
|
2621
|
+
c = {
|
|
2622
|
+
...c,
|
|
2659
2623
|
...hookRes.context
|
|
2660
2624
|
};
|
|
2661
2625
|
}
|
|
@@ -2666,7 +2630,7 @@ function getEndpoints(ctx, options) {
|
|
|
2666
2630
|
const endpointRes = await value({
|
|
2667
2631
|
...context,
|
|
2668
2632
|
context: {
|
|
2669
|
-
...
|
|
2633
|
+
...c,
|
|
2670
2634
|
...context.context
|
|
2671
2635
|
}
|
|
2672
2636
|
});
|
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, k as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth } from '../index-
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, k as Organization, M as Member, I as Invitation, u as username, m as magicLink, d as phoneNumber, e as anonymous, i as admin, j as genericOAuth } from '../index-e3_mbU9X.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-e3_mbU9X.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-DLbRYrL5.js';
|
|
9
9
|
import '../types-IzAbV4nB.js';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import 'better-call';
|
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-DLbRYrL5.js';
|
|
10
10
|
import 'kysely';
|
|
11
11
|
import './types-IzAbV4nB.js';
|
|
12
12
|
import 'better-call';
|
package/dist/client.js
CHANGED
|
@@ -56,10 +56,6 @@ var redirectPlugin = {
|
|
|
56
56
|
name: "Redirect",
|
|
57
57
|
hooks: {
|
|
58
58
|
onSuccess(context) {
|
|
59
|
-
const header = context.response?.headers.get("x-auth-redirect");
|
|
60
|
-
if (!header) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
59
|
if (context.data?.url && context.data?.redirect) {
|
|
64
60
|
if (typeof window !== "undefined") {
|
|
65
61
|
window.location.href = context.data.url;
|
|
@@ -118,9 +114,9 @@ var csrfPlugin = {
|
|
|
118
114
|
);
|
|
119
115
|
}
|
|
120
116
|
const csrfToken = data?.csrfToken;
|
|
121
|
-
options.
|
|
122
|
-
...options
|
|
123
|
-
|
|
117
|
+
options.body = {
|
|
118
|
+
...options?.body,
|
|
119
|
+
csrfToken
|
|
124
120
|
};
|
|
125
121
|
}
|
|
126
122
|
options.credentials = "include";
|