better-auth 1.2.0-beta.5 → 1.2.0-beta.6
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.cjs +3 -3
- package/dist/adapters/drizzle.d.cts +1 -1
- package/dist/adapters/drizzle.d.ts +1 -1
- package/dist/adapters/drizzle.js +1 -1
- package/dist/adapters/kysely.cjs +3 -3
- package/dist/adapters/kysely.d.cts +1 -1
- package/dist/adapters/kysely.d.ts +1 -1
- package/dist/adapters/kysely.js +1 -1
- package/dist/adapters/memory.cjs +2 -2
- package/dist/adapters/memory.d.cts +1 -1
- package/dist/adapters/memory.d.ts +1 -1
- package/dist/adapters/memory.js +1 -1
- package/dist/adapters/mongodb.cjs +3 -3
- package/dist/adapters/mongodb.d.cts +1 -1
- package/dist/adapters/mongodb.d.ts +1 -1
- package/dist/adapters/mongodb.js +1 -1
- package/dist/adapters/prisma.cjs +3 -3
- package/dist/adapters/prisma.d.cts +1 -1
- package/dist/adapters/prisma.d.ts +1 -1
- package/dist/adapters/prisma.js +1 -1
- package/dist/adapters/test.d.cts +1 -1
- package/dist/adapters/test.d.ts +1 -1
- package/dist/api.cjs +41 -41
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/{auth-BIKkqX3w.d.ts → auth-BfbTouIV.d.ts} +5 -5
- package/dist/{auth-DYJ8ix3G.d.cts → auth-CC4kpwks.d.cts} +5 -5
- package/dist/{chunk-7P2P7Y35.js → chunk-2F3IX7O2.js} +1 -1
- package/dist/{chunk-VG5Y5QXC.js → chunk-4KMR5H5T.js} +1 -1
- package/dist/{chunk-XXGFGD3E.js → chunk-52TDJNDX.js} +11 -10
- package/dist/{chunk-YTMPZIP7.js → chunk-5AOJMBJI.js} +25 -3
- package/dist/{chunk-HQFWDJO3.cjs → chunk-5ECP2UE2.cjs} +5 -5
- package/dist/{chunk-VLA6IUW4.js → chunk-5G6XUCMS.js} +51 -2
- package/dist/{chunk-7H42DKFN.cjs → chunk-5KTUVZ3H.cjs} +5 -5
- package/dist/{chunk-QBBUTLKA.cjs → chunk-5RR5WN52.cjs} +5 -5
- package/dist/{chunk-XWK7ZOPU.cjs → chunk-75SPUXMY.cjs} +8 -8
- package/dist/{chunk-5LTLUS6A.js → chunk-BZOIXJ2Q.js} +1 -1
- package/dist/{chunk-SOFKSYNA.js → chunk-CG2CK6HR.js} +1 -1
- package/dist/{chunk-YZFX73MG.cjs → chunk-DURU7ZRA.cjs} +20 -20
- package/dist/{chunk-CLHJAEU2.js → chunk-EQYRCOOF.js} +5 -2
- package/dist/{chunk-IBIVHEIM.js → chunk-FX2ZHENM.js} +1 -1
- package/dist/{chunk-G6W6UQWJ.js → chunk-GWJDRQJ3.js} +2 -2
- package/dist/{chunk-C5LREWPU.cjs → chunk-HUDPJXOF.cjs} +24 -24
- package/dist/{chunk-DSB4P3WF.cjs → chunk-IUGQVFPG.cjs} +6 -6
- package/dist/{chunk-K46S33M5.cjs → chunk-K6WRBJAV.cjs} +3 -3
- package/dist/{chunk-C37NPGBI.cjs → chunk-KAEQXMEV.cjs} +46 -46
- package/dist/{chunk-CV5JTF37.cjs → chunk-KAR56MJZ.cjs} +5 -2
- package/dist/{chunk-6FRITF4C.cjs → chunk-LIGJVOZ4.cjs} +4 -4
- package/dist/{chunk-WKBV4PRW.cjs → chunk-MKNDCNWD.cjs} +3 -3
- package/dist/{chunk-WKXM7XUV.cjs → chunk-N7UWN6ND.cjs} +16 -4
- package/dist/{chunk-TV24P5IW.cjs → chunk-OALLKKNX.cjs} +52 -30
- package/dist/{chunk-3BXU3Z5H.js → chunk-QKCLO6S5.js} +1 -1
- package/dist/{chunk-E3CHTKRP.js → chunk-QLKU77BF.js} +1 -1
- package/dist/{chunk-CYI7H6T2.js → chunk-RMPI2YZ3.js} +1 -1
- package/dist/{chunk-R62AOMGV.js → chunk-SCXZXQTZ.js} +16 -4
- package/dist/{chunk-G365UCY7.js → chunk-ST2CQ4A2.js} +2 -2
- package/dist/{chunk-5RIBF22K.cjs → chunk-U44XLDNH.cjs} +22 -21
- package/dist/{chunk-OLGASOBP.cjs → chunk-UZNKBUDH.cjs} +11 -11
- package/dist/{chunk-7S7YLBK4.js → chunk-V56HFQQX.js} +1 -1
- package/dist/{chunk-HCHSHY7R.cjs → chunk-WD65CNWK.cjs} +77 -28
- package/dist/{chunk-H4A3GCFC.cjs → chunk-XKCN2VRG.cjs} +5 -5
- package/dist/{chunk-QG2HKEKG.js → chunk-XREMX2NV.js} +1 -1
- package/dist/{chunk-MHZNWING.js → chunk-ZDYKAJ67.js} +110 -2
- package/dist/{chunk-6QI5735F.js → chunk-ZKMUJOIP.js} +1 -1
- package/dist/{chunk-LHWLPZ6K.cjs → chunk-ZUUQ3FFY.cjs} +113 -5
- package/dist/client/plugins.d.cts +2 -2
- package/dist/client/plugins.d.ts +2 -2
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/cookies.d.cts +1 -1
- package/dist/cookies.d.ts +1 -1
- package/dist/db.cjs +12 -12
- package/dist/db.d.cts +2 -2
- package/dist/db.d.ts +2 -2
- package/dist/db.js +1 -1
- package/dist/{index-DOB91DVD.d.ts → index-CtbEb8Ls.d.ts} +107 -1
- package/dist/{index-BL6paKGE.d.cts → index-F5NLq5XF.d.cts} +107 -1
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/next-js.cjs +20 -20
- package/dist/next-js.d.cts +1 -1
- package/dist/next-js.d.ts +1 -1
- package/dist/next-js.js +19 -19
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/oauth2.d.cts +2 -2
- package/dist/oauth2.d.ts +2 -2
- package/dist/plugins/admin.cjs +3 -3
- package/dist/plugins/admin.d.cts +64 -8
- package/dist/plugins/admin.d.ts +64 -8
- package/dist/plugins/admin.js +2 -2
- package/dist/plugins/anonymous.cjs +3 -3
- package/dist/plugins/anonymous.d.cts +1 -1
- package/dist/plugins/anonymous.d.ts +1 -1
- package/dist/plugins/anonymous.js +2 -2
- package/dist/plugins/bearer.cjs +3 -3
- package/dist/plugins/bearer.d.cts +1 -1
- package/dist/plugins/bearer.d.ts +1 -1
- package/dist/plugins/bearer.js +2 -2
- package/dist/plugins/custom-session.cjs +3 -3
- package/dist/plugins/custom-session.d.cts +1 -1
- package/dist/plugins/custom-session.d.ts +1 -1
- package/dist/plugins/custom-session.js +2 -2
- package/dist/plugins/email-otp.cjs +3 -3
- package/dist/plugins/email-otp.d.cts +1 -1
- package/dist/plugins/email-otp.d.ts +1 -1
- package/dist/plugins/email-otp.js +2 -2
- package/dist/plugins/generic-oauth.cjs +3 -3
- package/dist/plugins/generic-oauth.d.cts +74 -1
- package/dist/plugins/generic-oauth.d.ts +74 -1
- package/dist/plugins/generic-oauth.js +2 -2
- package/dist/plugins/jwt.cjs +3 -3
- package/dist/plugins/jwt.d.cts +1 -1
- package/dist/plugins/jwt.d.ts +1 -1
- package/dist/plugins/jwt.js +2 -2
- package/dist/plugins/magic-link.cjs +3 -3
- package/dist/plugins/magic-link.d.cts +4 -0
- package/dist/plugins/magic-link.d.ts +4 -0
- package/dist/plugins/magic-link.js +2 -2
- package/dist/plugins/multi-session.cjs +3 -3
- package/dist/plugins/multi-session.d.cts +1 -1
- package/dist/plugins/multi-session.d.ts +1 -1
- package/dist/plugins/multi-session.js +2 -2
- package/dist/plugins/oidc-provider.cjs +3 -3
- package/dist/plugins/oidc-provider.js +2 -2
- package/dist/plugins/one-tap.cjs +3 -3
- package/dist/plugins/one-tap.js +2 -2
- package/dist/plugins/open-api.cjs +4 -4
- package/dist/plugins/open-api.d.cts +1 -1
- package/dist/plugins/open-api.d.ts +1 -1
- package/dist/plugins/open-api.js +3 -3
- package/dist/plugins/organization.cjs +3 -3
- package/dist/plugins/organization.d.cts +2 -2
- package/dist/plugins/organization.d.ts +2 -2
- package/dist/plugins/organization.js +2 -2
- package/dist/plugins/passkey.cjs +14 -14
- package/dist/plugins/passkey.d.cts +1 -1
- package/dist/plugins/passkey.d.ts +1 -1
- package/dist/plugins/passkey.js +1 -1
- package/dist/plugins/phone-number.cjs +3 -3
- package/dist/plugins/phone-number.d.cts +2 -2
- package/dist/plugins/phone-number.d.ts +2 -2
- package/dist/plugins/phone-number.js +2 -2
- package/dist/plugins/sso.cjs +9 -9
- package/dist/plugins/sso.d.cts +1 -1
- package/dist/plugins/sso.d.ts +1 -1
- package/dist/plugins/sso.js +1 -1
- package/dist/plugins/two-factor.cjs +3 -3
- package/dist/plugins/two-factor.d.cts +1 -1
- package/dist/plugins/two-factor.d.ts +1 -1
- package/dist/plugins/two-factor.js +2 -2
- package/dist/plugins/username.cjs +3 -3
- package/dist/plugins/username.d.cts +1 -1
- package/dist/plugins/username.d.ts +1 -1
- package/dist/plugins/username.js +2 -2
- package/dist/plugins.cjs +39 -39
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/plugins.js +19 -19
- package/dist/react.d.cts +2 -3
- package/dist/react.d.ts +2 -3
- package/dist/solid.d.cts +1 -1
- package/dist/solid.d.ts +1 -1
- package/dist/{state-DXzHe8jb.d.ts → state-BlyN0kTT.d.ts} +1 -1
- package/dist/{state-CEqdZ_y_.d.cts → state-ClV1x8my.d.cts} +1 -1
- package/dist/svelte-kit.d.cts +1 -1
- package/dist/svelte-kit.d.ts +1 -1
- package/dist/svelte.d.cts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.ts +3 -3
- package/dist/vue.d.cts +1 -1
- package/dist/vue.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEndpointResponse } from './chunk-JEYF2ARX.js';
|
|
2
|
-
import { createAuthMiddleware, getSessionFromCtx, APIError, createAuthEndpoint } from './chunk-
|
|
2
|
+
import { createAuthMiddleware, getSessionFromCtx, APIError, createAuthEndpoint } from './chunk-SCXZXQTZ.js';
|
|
3
3
|
import { deleteSessionCookie, setSessionCookie } from './chunk-QQGZ3XGI.js';
|
|
4
4
|
import { mergeSchema } from './chunk-HZBNUY7E.js';
|
|
5
5
|
import { getDate } from './chunk-FURNA6HY.js';
|
|
@@ -50,8 +50,7 @@ var admin = (options) => {
|
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
52
|
data: {
|
|
53
|
-
role: options?.defaultRole ?? "user"
|
|
54
|
-
...user
|
|
53
|
+
role: options?.defaultRole ?? "user"
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
56
|
}
|
|
@@ -766,6 +765,29 @@ var admin = (options) => {
|
|
|
766
765
|
success: true
|
|
767
766
|
});
|
|
768
767
|
}
|
|
768
|
+
),
|
|
769
|
+
setUserPassword: createAuthEndpoint(
|
|
770
|
+
"/admin/set-user-password",
|
|
771
|
+
{
|
|
772
|
+
method: "POST",
|
|
773
|
+
body: z.object({
|
|
774
|
+
newPassword: z.string(),
|
|
775
|
+
userId: z.string()
|
|
776
|
+
}),
|
|
777
|
+
use: [adminMiddleware]
|
|
778
|
+
},
|
|
779
|
+
async (ctx) => {
|
|
780
|
+
const hashedPassword = await ctx.context.password.hash(
|
|
781
|
+
ctx.body.newPassword
|
|
782
|
+
);
|
|
783
|
+
await ctx.context.internalAdapter.updatePassword(
|
|
784
|
+
ctx.body.userId,
|
|
785
|
+
hashedPassword
|
|
786
|
+
);
|
|
787
|
+
return ctx.json({
|
|
788
|
+
status: true
|
|
789
|
+
});
|
|
790
|
+
}
|
|
769
791
|
)
|
|
770
792
|
},
|
|
771
793
|
$ERROR_CODES: ERROR_CODES,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN7UWN6ND_cjs = require('./chunk-N7UWN6ND.cjs');
|
|
4
4
|
var chunkS5UORXJH_cjs = require('./chunk-S5UORXJH.cjs');
|
|
5
5
|
var chunkV6HE2MP7_cjs = require('./chunk-V6HE2MP7.cjs');
|
|
6
6
|
var chunkB5UCLTPZ_cjs = require('./chunk-B5UCLTPZ.cjs');
|
|
@@ -25,7 +25,7 @@ var anonymous = (options) => {
|
|
|
25
25
|
return {
|
|
26
26
|
id: "anonymous",
|
|
27
27
|
endpoints: {
|
|
28
|
-
signInAnonymous:
|
|
28
|
+
signInAnonymous: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
29
29
|
"/sign-in/anonymous",
|
|
30
30
|
{
|
|
31
31
|
method: "POST",
|
|
@@ -109,14 +109,14 @@ var anonymous = (options) => {
|
|
|
109
109
|
matcher(ctx) {
|
|
110
110
|
return ctx.path.startsWith("/sign-in") || ctx.path.startsWith("/sign-up") || ctx.path.startsWith("/callback") || ctx.path.startsWith("/oauth2/callback") || ctx.path.startsWith("/magic-link/verify") || ctx.path.startsWith("/email-otp/verify-email");
|
|
111
111
|
},
|
|
112
|
-
handler:
|
|
112
|
+
handler: chunkN7UWN6ND_cjs.createAuthMiddleware(async (ctx) => {
|
|
113
113
|
const setCookie = ctx.context.responseHeaders?.get("set-cookie");
|
|
114
114
|
const sessionTokenName = ctx.context.authCookies.sessionToken.name;
|
|
115
115
|
const sessionCookie = chunkV6HE2MP7_cjs.parseSetCookieHeader(setCookie || "").get(sessionTokenName)?.value.split(".")[0];
|
|
116
116
|
if (!sessionCookie) {
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
const session = await
|
|
119
|
+
const session = await chunkN7UWN6ND_cjs.getSessionFromCtx(
|
|
120
120
|
ctx,
|
|
121
121
|
{
|
|
122
122
|
disableRefresh: true
|
|
@@ -126,7 +126,7 @@ var anonymous = (options) => {
|
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
128
|
if (ctx.path === "/sign-in/anonymous") {
|
|
129
|
-
throw new
|
|
129
|
+
throw new chunkN7UWN6ND_cjs.APIError("BAD_REQUEST", {
|
|
130
130
|
message: ERROR_CODES.ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY
|
|
131
131
|
});
|
|
132
132
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultRoles } from './chunk-GBLEGHZW.js';
|
|
2
|
-
import { createAuthMiddleware, sessionMiddleware, createAuthEndpoint, getSessionFromCtx, requestOnlySessionMiddleware, BASE_ERROR_CODES } from './chunk-
|
|
2
|
+
import { createAuthMiddleware, sessionMiddleware, createAuthEndpoint, getSessionFromCtx, requestOnlySessionMiddleware, BASE_ERROR_CODES } from './chunk-SCXZXQTZ.js';
|
|
3
3
|
import { parser_default } from './chunk-HVHN3Y2L.js';
|
|
4
4
|
import { setSessionCookie } from './chunk-QQGZ3XGI.js';
|
|
5
5
|
import { generateId } from './chunk-KLDFBLYL.js';
|
|
@@ -1364,6 +1364,54 @@ var getActiveMember = createAuthEndpoint(
|
|
|
1364
1364
|
return ctx.json(member);
|
|
1365
1365
|
}
|
|
1366
1366
|
);
|
|
1367
|
+
var leaveOrganization = createAuthEndpoint(
|
|
1368
|
+
"/organization/leave",
|
|
1369
|
+
{
|
|
1370
|
+
method: "POST",
|
|
1371
|
+
body: z.object({
|
|
1372
|
+
organizationId: z.string()
|
|
1373
|
+
}),
|
|
1374
|
+
use: [sessionMiddleware, orgMiddleware]
|
|
1375
|
+
},
|
|
1376
|
+
async (ctx) => {
|
|
1377
|
+
const session = ctx.context.session;
|
|
1378
|
+
const adapter = getOrgAdapter(ctx.context);
|
|
1379
|
+
const member = await adapter.findMemberByOrgId({
|
|
1380
|
+
userId: session.user.id,
|
|
1381
|
+
organizationId: ctx.body.organizationId
|
|
1382
|
+
});
|
|
1383
|
+
if (!member) {
|
|
1384
|
+
throw new APIError("BAD_REQUEST", {
|
|
1385
|
+
message: ORGANIZATION_ERROR_CODES.MEMBER_NOT_FOUND
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
const isOwnerLeaving = member.role === (ctx.context.orgOptions?.creatorRole || "owner");
|
|
1389
|
+
if (isOwnerLeaving) {
|
|
1390
|
+
const members = await ctx.context.adapter.findMany({
|
|
1391
|
+
model: "member",
|
|
1392
|
+
where: [
|
|
1393
|
+
{
|
|
1394
|
+
field: "organizationId",
|
|
1395
|
+
value: ctx.body.organizationId
|
|
1396
|
+
}
|
|
1397
|
+
]
|
|
1398
|
+
});
|
|
1399
|
+
const owners = members.filter(
|
|
1400
|
+
(member2) => member2.role === (ctx.context.orgOptions?.creatorRole || "owner")
|
|
1401
|
+
);
|
|
1402
|
+
if (owners.length <= 1) {
|
|
1403
|
+
throw new APIError("BAD_REQUEST", {
|
|
1404
|
+
message: ORGANIZATION_ERROR_CODES.YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
await adapter.deleteMember(member.id);
|
|
1409
|
+
if (session.session.activeOrganizationId === ctx.body.organizationId) {
|
|
1410
|
+
await adapter.setActiveOrganization(session.session.token, null);
|
|
1411
|
+
}
|
|
1412
|
+
return ctx.json(member);
|
|
1413
|
+
}
|
|
1414
|
+
);
|
|
1367
1415
|
var createOrganization = createAuthEndpoint(
|
|
1368
1416
|
"/organization/create",
|
|
1369
1417
|
{
|
|
@@ -1887,7 +1935,8 @@ var organization = (options) => {
|
|
|
1887
1935
|
addMember: addMember(),
|
|
1888
1936
|
removeMember,
|
|
1889
1937
|
updateMemberRole: updateMemberRole(),
|
|
1890
|
-
getActiveMember
|
|
1938
|
+
getActiveMember,
|
|
1939
|
+
leaveOrganization
|
|
1891
1940
|
};
|
|
1892
1941
|
const roles = {
|
|
1893
1942
|
...defaultRoles,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN7UWN6ND_cjs = require('./chunk-N7UWN6ND.cjs');
|
|
4
4
|
var chunkS5UORXJH_cjs = require('./chunk-S5UORXJH.cjs');
|
|
5
5
|
var chunkG2LZ73E2_cjs = require('./chunk-G2LZ73E2.cjs');
|
|
6
6
|
var chunkVXYIYABQ_cjs = require('./chunk-VXYIYABQ.cjs');
|
|
@@ -19,7 +19,7 @@ var oAuthProxy = (opts) => {
|
|
|
19
19
|
return {
|
|
20
20
|
id: "oauth-proxy",
|
|
21
21
|
endpoints: {
|
|
22
|
-
oAuthProxy:
|
|
22
|
+
oAuthProxy: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
23
23
|
"/oauth-proxy-callback",
|
|
24
24
|
{
|
|
25
25
|
method: "GET",
|
|
@@ -31,7 +31,7 @@ var oAuthProxy = (opts) => {
|
|
|
31
31
|
description: "The cookies to set after the proxy"
|
|
32
32
|
})
|
|
33
33
|
}),
|
|
34
|
-
use: [
|
|
34
|
+
use: [chunkN7UWN6ND_cjs.originCheck((ctx) => ctx.query.callbackURL)],
|
|
35
35
|
metadata: {
|
|
36
36
|
openapi: {
|
|
37
37
|
description: "OAuth Proxy Callback",
|
|
@@ -82,7 +82,7 @@ var oAuthProxy = (opts) => {
|
|
|
82
82
|
matcher(context) {
|
|
83
83
|
return context.path?.startsWith("/callback");
|
|
84
84
|
},
|
|
85
|
-
handler:
|
|
85
|
+
handler: chunkN7UWN6ND_cjs.createAuthMiddleware(async (ctx) => {
|
|
86
86
|
const headers = ctx.context.responseHeaders;
|
|
87
87
|
const location = headers?.get("location");
|
|
88
88
|
if (location?.includes("/oauth-proxy-callback?callbackURL")) {
|
|
@@ -120,7 +120,7 @@ var oAuthProxy = (opts) => {
|
|
|
120
120
|
matcher(context) {
|
|
121
121
|
return context.path?.startsWith("/sign-in/social");
|
|
122
122
|
},
|
|
123
|
-
handler:
|
|
123
|
+
handler: chunkN7UWN6ND_cjs.createAuthMiddleware(async (ctx) => {
|
|
124
124
|
const url = new URL(
|
|
125
125
|
opts?.currentURL || ctx.request?.url || getVenderBaseURL() || ctx.context.baseURL
|
|
126
126
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkN7UWN6ND_cjs = require('./chunk-N7UWN6ND.cjs');
|
|
4
4
|
var chunkB5UCLTPZ_cjs = require('./chunk-B5UCLTPZ.cjs');
|
|
5
5
|
var chunkG2LZ73E2_cjs = require('./chunk-G2LZ73E2.cjs');
|
|
6
6
|
var zod = require('zod');
|
|
@@ -117,7 +117,7 @@ var jwt = (options) => {
|
|
|
117
117
|
return {
|
|
118
118
|
id: "jwt",
|
|
119
119
|
endpoints: {
|
|
120
|
-
getJwks:
|
|
120
|
+
getJwks: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
121
121
|
"/jwks",
|
|
122
122
|
{
|
|
123
123
|
method: "GET",
|
|
@@ -213,12 +213,12 @@ var jwt = (options) => {
|
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
),
|
|
216
|
-
getToken:
|
|
216
|
+
getToken: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
217
217
|
"/token",
|
|
218
218
|
{
|
|
219
219
|
method: "GET",
|
|
220
220
|
requireHeaders: true,
|
|
221
|
-
use: [
|
|
221
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware],
|
|
222
222
|
metadata: {
|
|
223
223
|
openapi: {
|
|
224
224
|
description: "Get a JWT token",
|
|
@@ -256,7 +256,7 @@ var jwt = (options) => {
|
|
|
256
256
|
matcher(context) {
|
|
257
257
|
return context.path === "/get-session";
|
|
258
258
|
},
|
|
259
|
-
handler:
|
|
259
|
+
handler: chunkN7UWN6ND_cjs.createAuthMiddleware(async (ctx) => {
|
|
260
260
|
const session = ctx.context.session;
|
|
261
261
|
if (session && session.session) {
|
|
262
262
|
const jwt2 = await getJwtToken(ctx);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkN7UWN6ND_cjs = require('./chunk-N7UWN6ND.cjs');
|
|
4
|
+
var chunkKAR56MJZ_cjs = require('./chunk-KAR56MJZ.cjs');
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
|
|
7
7
|
var paths = {};
|
|
@@ -180,11 +180,11 @@ function getResponse(responses) {
|
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
182
|
async function generator(ctx, options) {
|
|
183
|
-
const baseEndpoints =
|
|
183
|
+
const baseEndpoints = chunkN7UWN6ND_cjs.getEndpoints(ctx, {
|
|
184
184
|
...options,
|
|
185
185
|
plugins: []
|
|
186
186
|
});
|
|
187
|
-
const tables =
|
|
187
|
+
const tables = chunkKAR56MJZ_cjs.getAuthTables(options);
|
|
188
188
|
const models = Object.entries(tables).reduce((acc, [key, value]) => {
|
|
189
189
|
const modelName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
190
190
|
acc[modelName] = {
|
|
@@ -260,7 +260,7 @@ async function generator(ctx, options) {
|
|
|
260
260
|
if (plugin.id === "open-api") {
|
|
261
261
|
continue;
|
|
262
262
|
}
|
|
263
|
-
const pluginEndpoints =
|
|
263
|
+
const pluginEndpoints = chunkN7UWN6ND_cjs.getEndpoints(ctx, {
|
|
264
264
|
...options,
|
|
265
265
|
plugins: [plugin]
|
|
266
266
|
});
|
|
@@ -390,7 +390,7 @@ var openAPI = (options) => {
|
|
|
390
390
|
return {
|
|
391
391
|
id: "open-api",
|
|
392
392
|
endpoints: {
|
|
393
|
-
generateOpenAPISchema:
|
|
393
|
+
generateOpenAPISchema: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
394
394
|
"/open-api/generate-schema",
|
|
395
395
|
{
|
|
396
396
|
method: "GET"
|
|
@@ -400,7 +400,7 @@ var openAPI = (options) => {
|
|
|
400
400
|
return ctx.json(schema);
|
|
401
401
|
}
|
|
402
402
|
),
|
|
403
|
-
openAPIReference:
|
|
403
|
+
openAPIReference: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
404
404
|
path,
|
|
405
405
|
{
|
|
406
406
|
method: "GET",
|
|
@@ -410,7 +410,7 @@ var openAPI = (options) => {
|
|
|
410
410
|
},
|
|
411
411
|
async (ctx) => {
|
|
412
412
|
if (options?.disableDefaultReference) {
|
|
413
|
-
throw new
|
|
413
|
+
throw new chunkN7UWN6ND_cjs.APIError("NOT_FOUND");
|
|
414
414
|
}
|
|
415
415
|
const schema = await generator(ctx.context, ctx.context.options);
|
|
416
416
|
return new Response(getHTML(schema), {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAuthMiddleware } from './chunk-
|
|
1
|
+
import { createAuthMiddleware } from './chunk-SCXZXQTZ.js';
|
|
2
2
|
import { parseSetCookieHeader } from './chunk-QQGZ3XGI.js';
|
|
3
3
|
import { serializeSignedCookie } from 'better-call';
|
|
4
4
|
import { createHMAC } from '@better-auth/utils/hmac';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TWO_FACTOR_ERROR_CODES } from './chunk-WMXBA6LX.js';
|
|
2
2
|
import { validatePassword } from './chunk-TOKZL3ZI.js';
|
|
3
|
-
import { createAuthMiddleware, getSessionFromCtx, createAuthEndpoint, sessionMiddleware, BASE_ERROR_CODES } from './chunk-
|
|
3
|
+
import { createAuthMiddleware, getSessionFromCtx, createAuthEndpoint, sessionMiddleware, BASE_ERROR_CODES } from './chunk-SCXZXQTZ.js';
|
|
4
4
|
import { setSessionCookie, deleteSessionCookie } from './chunk-QQGZ3XGI.js';
|
|
5
5
|
import { mergeSchema } from './chunk-HZBNUY7E.js';
|
|
6
6
|
import { generateRandomString, symmetricEncrypt, symmetricDecrypt } from './chunk-DBPOZRMS.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkZBKCS3KP_cjs = require('./chunk-ZBKCS3KP.cjs');
|
|
4
4
|
var chunkEHFDU6IF_cjs = require('./chunk-EHFDU6IF.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkN7UWN6ND_cjs = require('./chunk-N7UWN6ND.cjs');
|
|
6
6
|
var chunkV6HE2MP7_cjs = require('./chunk-V6HE2MP7.cjs');
|
|
7
7
|
var chunkB5UCLTPZ_cjs = require('./chunk-B5UCLTPZ.cjs');
|
|
8
8
|
var chunkG2LZ73E2_cjs = require('./chunk-G2LZ73E2.cjs');
|
|
@@ -14,7 +14,7 @@ var otp = require('@better-auth/utils/otp');
|
|
|
14
14
|
// src/plugins/two-factor/constant.ts
|
|
15
15
|
var TWO_FACTOR_COOKIE_NAME = "two_factor";
|
|
16
16
|
var TRUST_DEVICE_COOKIE_NAME = "trust_device";
|
|
17
|
-
var verifyTwoFactorMiddleware =
|
|
17
|
+
var verifyTwoFactorMiddleware = chunkN7UWN6ND_cjs.createAuthMiddleware(
|
|
18
18
|
{
|
|
19
19
|
body: zod.z.object({
|
|
20
20
|
/**
|
|
@@ -26,7 +26,7 @@ var verifyTwoFactorMiddleware = chunkWKXM7XUV_cjs.createAuthMiddleware(
|
|
|
26
26
|
})
|
|
27
27
|
},
|
|
28
28
|
async (ctx) => {
|
|
29
|
-
const session = await
|
|
29
|
+
const session = await chunkN7UWN6ND_cjs.getSessionFromCtx(ctx);
|
|
30
30
|
if (!session) {
|
|
31
31
|
const cookieName = ctx.context.createAuthCookie(TWO_FACTOR_COOKIE_NAME);
|
|
32
32
|
const userId = await ctx.getSignedCookie(
|
|
@@ -172,7 +172,7 @@ var backupCode2fa = (options) => {
|
|
|
172
172
|
return {
|
|
173
173
|
id: "backup_code",
|
|
174
174
|
endpoints: {
|
|
175
|
-
verifyBackupCode:
|
|
175
|
+
verifyBackupCode: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
176
176
|
"/two-factor/verify-backup-code",
|
|
177
177
|
{
|
|
178
178
|
method: "POST",
|
|
@@ -241,14 +241,14 @@ var backupCode2fa = (options) => {
|
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
),
|
|
244
|
-
generateBackupCodes:
|
|
244
|
+
generateBackupCodes: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
245
245
|
"/two-factor/generate-backup-codes",
|
|
246
246
|
{
|
|
247
247
|
method: "POST",
|
|
248
248
|
body: zod.z.object({
|
|
249
249
|
password: zod.z.string()
|
|
250
250
|
}),
|
|
251
|
-
use: [
|
|
251
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware]
|
|
252
252
|
},
|
|
253
253
|
async (ctx) => {
|
|
254
254
|
const user = ctx.context.session.user;
|
|
@@ -280,7 +280,7 @@ var backupCode2fa = (options) => {
|
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
282
|
),
|
|
283
|
-
viewBackupCodes:
|
|
283
|
+
viewBackupCodes: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
284
284
|
"/two-factor/view-backup-codes",
|
|
285
285
|
{
|
|
286
286
|
method: "GET",
|
|
@@ -331,7 +331,7 @@ var otp2fa = (options) => {
|
|
|
331
331
|
period: (options?.period || 3) * 60 * 1e3
|
|
332
332
|
};
|
|
333
333
|
const twoFactorTable = "twoFactor";
|
|
334
|
-
const send2FaOTP =
|
|
334
|
+
const send2FaOTP = chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
335
335
|
"/two-factor/send-otp",
|
|
336
336
|
{
|
|
337
337
|
method: "POST",
|
|
@@ -402,7 +402,7 @@ var otp2fa = (options) => {
|
|
|
402
402
|
return ctx.json({ status: true });
|
|
403
403
|
}
|
|
404
404
|
);
|
|
405
|
-
const verifyOTP =
|
|
405
|
+
const verifyOTP = chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
406
406
|
"/two-factor/verify-otp",
|
|
407
407
|
{
|
|
408
408
|
method: "POST",
|
|
@@ -493,11 +493,11 @@ var totp2fa = (options) => {
|
|
|
493
493
|
period: options?.period || 30
|
|
494
494
|
};
|
|
495
495
|
const twoFactorTable = "twoFactor";
|
|
496
|
-
const generateTOTP =
|
|
496
|
+
const generateTOTP = chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
497
497
|
"/totp/generate",
|
|
498
498
|
{
|
|
499
499
|
method: "POST",
|
|
500
|
-
use: [
|
|
500
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware],
|
|
501
501
|
metadata: {
|
|
502
502
|
openapi: {
|
|
503
503
|
summary: "Generate TOTP code",
|
|
@@ -553,11 +553,11 @@ var totp2fa = (options) => {
|
|
|
553
553
|
return { code };
|
|
554
554
|
}
|
|
555
555
|
);
|
|
556
|
-
const getTOTPURI =
|
|
556
|
+
const getTOTPURI = chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
557
557
|
"/two-factor/get-totp-uri",
|
|
558
558
|
{
|
|
559
559
|
method: "POST",
|
|
560
|
-
use: [
|
|
560
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware],
|
|
561
561
|
body: zod.z.object({
|
|
562
562
|
password: zod.z.string({
|
|
563
563
|
description: "User password"
|
|
@@ -625,7 +625,7 @@ var totp2fa = (options) => {
|
|
|
625
625
|
};
|
|
626
626
|
}
|
|
627
627
|
);
|
|
628
|
-
const verifyTOTP =
|
|
628
|
+
const verifyTOTP = chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
629
629
|
"/two-factor/verify-totp",
|
|
630
630
|
{
|
|
631
631
|
method: "POST",
|
|
@@ -779,7 +779,7 @@ var twoFactor = (options) => {
|
|
|
779
779
|
...totp.endpoints,
|
|
780
780
|
...otp$1.endpoints,
|
|
781
781
|
...backupCode.endpoints,
|
|
782
|
-
enableTwoFactor:
|
|
782
|
+
enableTwoFactor: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
783
783
|
"/two-factor/enable",
|
|
784
784
|
{
|
|
785
785
|
method: "POST",
|
|
@@ -788,7 +788,7 @@ var twoFactor = (options) => {
|
|
|
788
788
|
description: "User password"
|
|
789
789
|
}).min(8)
|
|
790
790
|
}),
|
|
791
|
-
use: [
|
|
791
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware],
|
|
792
792
|
metadata: {
|
|
793
793
|
openapi: {
|
|
794
794
|
summary: "Enable two factor authentication",
|
|
@@ -830,7 +830,7 @@ var twoFactor = (options) => {
|
|
|
830
830
|
});
|
|
831
831
|
if (!isPasswordValid) {
|
|
832
832
|
throw new betterCall.APIError("BAD_REQUEST", {
|
|
833
|
-
message:
|
|
833
|
+
message: chunkN7UWN6ND_cjs.BASE_ERROR_CODES.INVALID_PASSWORD
|
|
834
834
|
});
|
|
835
835
|
}
|
|
836
836
|
const secret = chunkG2LZ73E2_cjs.generateRandomString(32);
|
|
@@ -887,7 +887,7 @@ var twoFactor = (options) => {
|
|
|
887
887
|
return ctx.json({ totpURI, backupCodes: backupCodes.backupCodes });
|
|
888
888
|
}
|
|
889
889
|
),
|
|
890
|
-
disableTwoFactor:
|
|
890
|
+
disableTwoFactor: chunkN7UWN6ND_cjs.createAuthEndpoint(
|
|
891
891
|
"/two-factor/disable",
|
|
892
892
|
{
|
|
893
893
|
method: "POST",
|
|
@@ -896,7 +896,7 @@ var twoFactor = (options) => {
|
|
|
896
896
|
description: "User password"
|
|
897
897
|
}).min(8)
|
|
898
898
|
}),
|
|
899
|
-
use: [
|
|
899
|
+
use: [chunkN7UWN6ND_cjs.sessionMiddleware],
|
|
900
900
|
metadata: {
|
|
901
901
|
openapi: {
|
|
902
902
|
summary: "Disable two factor authentication",
|
|
@@ -972,7 +972,7 @@ var twoFactor = (options) => {
|
|
|
972
972
|
matcher(context) {
|
|
973
973
|
return context.path === "/sign-in/email" || context.path === "/sign-in/username" || context.path === "/sign-in/phone-number";
|
|
974
974
|
},
|
|
975
|
-
handler:
|
|
975
|
+
handler: chunkN7UWN6ND_cjs.createAuthMiddleware(async (ctx) => {
|
|
976
976
|
const data = ctx.context.newSession;
|
|
977
977
|
if (!data) {
|
|
978
978
|
return;
|
|
@@ -90,13 +90,16 @@ function getWithHooks(adapter, ctx) {
|
|
|
90
90
|
for (const hook of hooks || []) {
|
|
91
91
|
const toRun = hook[model]?.create?.before;
|
|
92
92
|
if (toRun) {
|
|
93
|
-
const result = await toRun(
|
|
93
|
+
const result = await toRun(actualData);
|
|
94
94
|
if (result === false) {
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
const isObject = typeof result === "object" && "data" in result;
|
|
98
98
|
if (isObject) {
|
|
99
|
-
actualData =
|
|
99
|
+
actualData = {
|
|
100
|
+
...actualData,
|
|
101
|
+
...result.data
|
|
102
|
+
};
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TWO_FACTOR_ERROR_CODES } from './chunk-WMXBA6LX.js';
|
|
2
|
-
import { createAuthEndpoint, sendVerificationEmailFn, BASE_ERROR_CODES, createAuthMiddleware } from './chunk-
|
|
2
|
+
import { createAuthEndpoint, sendVerificationEmailFn, BASE_ERROR_CODES, createAuthMiddleware } from './chunk-SCXZXQTZ.js';
|
|
3
3
|
import { setSessionCookie } from './chunk-QQGZ3XGI.js';
|
|
4
4
|
import { mergeSchema } from './chunk-HZBNUY7E.js';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createAuthEndpoint, APIError, getEndpoints } from './chunk-
|
|
2
|
-
import { getAuthTables } from './chunk-
|
|
1
|
+
import { createAuthEndpoint, APIError, getEndpoints } from './chunk-SCXZXQTZ.js';
|
|
2
|
+
import { getAuthTables } from './chunk-EQYRCOOF.js';
|
|
3
3
|
import { ZodObject, ZodSchema, ZodOptional } from 'zod';
|
|
4
4
|
|
|
5
5
|
var paths = {};
|