better-auth 1.2.3-beta.1 → 1.2.3-beta.3
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/integrations/next-js.cjs +0 -1
- package/dist/integrations/next-js.mjs +0 -1
- package/dist/plugins/admin/index.cjs +1 -2
- package/dist/plugins/admin/index.d.cts +9 -0
- package/dist/plugins/admin/index.d.mts +9 -0
- package/dist/plugins/admin/index.d.ts +9 -0
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/index.cjs +1 -2
- package/dist/plugins/index.mjs +1 -2
- package/dist/plugins/multi-session/index.cjs +3 -3
- package/dist/plugins/multi-session/index.mjs +3 -3
- package/dist/shared/{better-auth.BxiPGoZk.cjs → better-auth.DXbPkpEx.cjs} +21 -12
- package/dist/shared/{better-auth.CMzBOV3L.mjs → better-auth.K251u4eV.mjs} +11 -2
- package/package.json +1 -1
- package/dist/shared/better-auth.DUb9p_mV.cjs +0 -23
- package/dist/shared/better-auth.Do0oI2pb.mjs +0 -21
|
@@ -24,7 +24,6 @@ require('@better-auth/utils/hex');
|
|
|
24
24
|
require('@noble/hashes/utils');
|
|
25
25
|
require('../shared/better-auth.CMz4USTt.cjs');
|
|
26
26
|
require('@better-auth/utils/otp');
|
|
27
|
-
require('../shared/better-auth.DUb9p_mV.cjs');
|
|
28
27
|
require('../plugins/admin/access/index.cjs');
|
|
29
28
|
require('@better-fetch/fetch');
|
|
30
29
|
require('@better-auth/utils/random');
|
|
@@ -22,7 +22,6 @@ import '@better-auth/utils/hex';
|
|
|
22
22
|
import '@noble/hashes/utils';
|
|
23
23
|
import '../shared/better-auth.Bd1H94Nk.mjs';
|
|
24
24
|
import '@better-auth/utils/otp';
|
|
25
|
-
import '../shared/better-auth.Do0oI2pb.mjs';
|
|
26
25
|
import '../plugins/admin/access/index.mjs';
|
|
27
26
|
import '@better-fetch/fetch';
|
|
28
27
|
import '@better-auth/utils/random';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const admin = require('../../shared/better-auth.
|
|
3
|
+
const admin = require('../../shared/better-auth.DXbPkpEx.cjs');
|
|
4
4
|
require('zod');
|
|
5
5
|
require('better-call');
|
|
6
6
|
require('../../shared/better-auth.BzKRBwSF.cjs');
|
|
@@ -35,7 +35,6 @@ require('../../shared/better-auth.DhfiEsxl.cjs');
|
|
|
35
35
|
require('jose/errors');
|
|
36
36
|
require('@better-auth/utils/binary');
|
|
37
37
|
require('../../shared/better-auth.DNqtHmvg.cjs');
|
|
38
|
-
require('../../shared/better-auth.DUb9p_mV.cjs');
|
|
39
38
|
require('./access/index.cjs');
|
|
40
39
|
require('../access/index.cjs');
|
|
41
40
|
|
|
@@ -24,6 +24,15 @@ interface AdminOptions {
|
|
|
24
24
|
* @default "user"
|
|
25
25
|
*/
|
|
26
26
|
defaultRole?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Roles that are considered admin roles.
|
|
29
|
+
*
|
|
30
|
+
* Any user role that isn't in this list, even if they have the permission,
|
|
31
|
+
* will not be considered an admin.
|
|
32
|
+
*
|
|
33
|
+
* @default ["admin"]
|
|
34
|
+
*/
|
|
35
|
+
adminRoles?: string | string[];
|
|
27
36
|
/**
|
|
28
37
|
* A default ban reason
|
|
29
38
|
*
|
|
@@ -24,6 +24,15 @@ interface AdminOptions {
|
|
|
24
24
|
* @default "user"
|
|
25
25
|
*/
|
|
26
26
|
defaultRole?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Roles that are considered admin roles.
|
|
29
|
+
*
|
|
30
|
+
* Any user role that isn't in this list, even if they have the permission,
|
|
31
|
+
* will not be considered an admin.
|
|
32
|
+
*
|
|
33
|
+
* @default ["admin"]
|
|
34
|
+
*/
|
|
35
|
+
adminRoles?: string | string[];
|
|
27
36
|
/**
|
|
28
37
|
* A default ban reason
|
|
29
38
|
*
|
|
@@ -24,6 +24,15 @@ interface AdminOptions {
|
|
|
24
24
|
* @default "user"
|
|
25
25
|
*/
|
|
26
26
|
defaultRole?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Roles that are considered admin roles.
|
|
29
|
+
*
|
|
30
|
+
* Any user role that isn't in this list, even if they have the permission,
|
|
31
|
+
* will not be considered an admin.
|
|
32
|
+
*
|
|
33
|
+
* @default ["admin"]
|
|
34
|
+
*/
|
|
35
|
+
adminRoles?: string | string[];
|
|
27
36
|
/**
|
|
28
37
|
* A default ban reason
|
|
29
38
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { a as admin } from '../../shared/better-auth.
|
|
1
|
+
export { a as admin } from '../../shared/better-auth.K251u4eV.mjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'better-call';
|
|
4
4
|
import '../../shared/better-auth.npe3WWSD.mjs';
|
|
@@ -33,6 +33,5 @@ import '../../shared/better-auth.NcLhHEks.mjs';
|
|
|
33
33
|
import 'jose/errors';
|
|
34
34
|
import '@better-auth/utils/binary';
|
|
35
35
|
import '../../shared/better-auth.DQI8AD7d.mjs';
|
|
36
|
-
import '../../shared/better-auth.Do0oI2pb.mjs';
|
|
37
36
|
import './access/index.mjs';
|
|
38
37
|
import '../access/index.mjs';
|
package/dist/plugins/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ const account = require('../shared/better-auth.BzKRBwSF.cjs');
|
|
|
8
8
|
const plugins_magicLink_index = require('./magic-link/index.cjs');
|
|
9
9
|
const plugins_phoneNumber_index = require('./phone-number/index.cjs');
|
|
10
10
|
const plugins_anonymous_index = require('./anonymous/index.cjs');
|
|
11
|
-
const admin = require('../shared/better-auth.
|
|
11
|
+
const admin = require('../shared/better-auth.DXbPkpEx.cjs');
|
|
12
12
|
const plugins_genericOauth_index = require('./generic-oauth/index.cjs');
|
|
13
13
|
const plugins_jwt_index = require('./jwt/index.cjs');
|
|
14
14
|
const plugins_multiSession_index = require('./multi-session/index.cjs');
|
|
@@ -65,7 +65,6 @@ require('../shared/better-auth.DhfiEsxl.cjs');
|
|
|
65
65
|
require('jose/errors');
|
|
66
66
|
require('@better-auth/utils/binary');
|
|
67
67
|
require('../shared/better-auth.DNqtHmvg.cjs');
|
|
68
|
-
require('../shared/better-auth.DUb9p_mV.cjs');
|
|
69
68
|
require('./admin/access/index.cjs');
|
|
70
69
|
require('../shared/better-auth.BG6vHVNT.cjs');
|
|
71
70
|
require('../api/index.cjs');
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ export { H as HIDE_METADATA, N as optionsMiddleware } from '../shared/better-aut
|
|
|
7
7
|
export { magicLink } from './magic-link/index.mjs';
|
|
8
8
|
export { phoneNumber } from './phone-number/index.mjs';
|
|
9
9
|
export { anonymous } from './anonymous/index.mjs';
|
|
10
|
-
export { a as admin } from '../shared/better-auth.
|
|
10
|
+
export { a as admin } from '../shared/better-auth.K251u4eV.mjs';
|
|
11
11
|
export { genericOAuth } from './generic-oauth/index.mjs';
|
|
12
12
|
export { getJwtToken, jwt } from './jwt/index.mjs';
|
|
13
13
|
export { multiSession } from './multi-session/index.mjs';
|
|
@@ -64,7 +64,6 @@ import '../shared/better-auth.NcLhHEks.mjs';
|
|
|
64
64
|
import 'jose/errors';
|
|
65
65
|
import '@better-auth/utils/binary';
|
|
66
66
|
import '../shared/better-auth.DQI8AD7d.mjs';
|
|
67
|
-
import '../shared/better-auth.Do0oI2pb.mjs';
|
|
68
67
|
import './admin/access/index.mjs';
|
|
69
68
|
import '../shared/better-auth.fsvwNeUx.mjs';
|
|
70
69
|
import '../api/index.mjs';
|
|
@@ -105,7 +105,7 @@ const multiSession = (options) => {
|
|
|
105
105
|
},
|
|
106
106
|
async (ctx) => {
|
|
107
107
|
const sessionToken = ctx.body.sessionToken;
|
|
108
|
-
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken}`;
|
|
108
|
+
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken.toLowerCase()}`;
|
|
109
109
|
const sessionCookie = await ctx.getSignedCookie(
|
|
110
110
|
multiSessionCookieName,
|
|
111
111
|
ctx.context.secret
|
|
@@ -254,8 +254,8 @@ const multiSession = (options) => {
|
|
|
254
254
|
...ctx.context.authCookies.sessionToken.options,
|
|
255
255
|
maxAge: 0
|
|
256
256
|
});
|
|
257
|
-
const
|
|
258
|
-
return
|
|
257
|
+
const token = cookies[key].split(".")[0];
|
|
258
|
+
return token;
|
|
259
259
|
}
|
|
260
260
|
return null;
|
|
261
261
|
}).filter((v) => v !== null);
|
|
@@ -103,7 +103,7 @@ const multiSession = (options) => {
|
|
|
103
103
|
},
|
|
104
104
|
async (ctx) => {
|
|
105
105
|
const sessionToken = ctx.body.sessionToken;
|
|
106
|
-
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken}`;
|
|
106
|
+
const multiSessionCookieName = `${ctx.context.authCookies.sessionToken.name}_multi-${sessionToken.toLowerCase()}`;
|
|
107
107
|
const sessionCookie = await ctx.getSignedCookie(
|
|
108
108
|
multiSessionCookieName,
|
|
109
109
|
ctx.context.secret
|
|
@@ -252,8 +252,8 @@ const multiSession = (options) => {
|
|
|
252
252
|
...ctx.context.authCookies.sessionToken.options,
|
|
253
253
|
maxAge: 0
|
|
254
254
|
});
|
|
255
|
-
const
|
|
256
|
-
return
|
|
255
|
+
const token = cookies[key].split(".")[0];
|
|
256
|
+
return token;
|
|
257
257
|
}
|
|
258
258
|
return null;
|
|
259
259
|
}).filter((v) => v !== null);
|
|
@@ -10,7 +10,6 @@ require('./better-auth.GpOOav9x.cjs');
|
|
|
10
10
|
require('defu');
|
|
11
11
|
const date = require('./better-auth.C1hdVENX.cjs');
|
|
12
12
|
const pluginHelper = require('./better-auth.DNqtHmvg.cjs');
|
|
13
|
-
const call = require('./better-auth.DUb9p_mV.cjs');
|
|
14
13
|
const plugins_admin_access_index = require('../plugins/admin/access/index.cjs');
|
|
15
14
|
|
|
16
15
|
const ADMIN_ERROR_CODES = {
|
|
@@ -47,8 +46,18 @@ const hasPermission = (input) => {
|
|
|
47
46
|
const admin = (options) => {
|
|
48
47
|
const opts = {
|
|
49
48
|
defaultRole: "user",
|
|
49
|
+
adminRoles: ["admin"],
|
|
50
50
|
...options
|
|
51
51
|
};
|
|
52
|
+
const adminMiddleware = account.createAuthMiddleware(async (ctx) => {
|
|
53
|
+
const session = await account.getSessionFromCtx(ctx);
|
|
54
|
+
if ((!session?.session || !opts.adminRoles.includes(session.user.role)) && !opts.adminUserIds?.includes(session?.user.id || "")) {
|
|
55
|
+
throw new betterCall.APIError("UNAUTHORIZED");
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
session
|
|
59
|
+
};
|
|
60
|
+
});
|
|
52
61
|
return {
|
|
53
62
|
id: "admin",
|
|
54
63
|
init(ctx) {
|
|
@@ -123,7 +132,7 @@ const admin = (options) => {
|
|
|
123
132
|
description: "The role to set. `admin` or `user` by default"
|
|
124
133
|
})
|
|
125
134
|
}),
|
|
126
|
-
use: [
|
|
135
|
+
use: [adminMiddleware],
|
|
127
136
|
metadata: {
|
|
128
137
|
openapi: {
|
|
129
138
|
operationId: "setRole",
|
|
@@ -201,7 +210,7 @@ const admin = (options) => {
|
|
|
201
210
|
})
|
|
202
211
|
)
|
|
203
212
|
}),
|
|
204
|
-
use: [
|
|
213
|
+
use: [adminMiddleware],
|
|
205
214
|
metadata: {
|
|
206
215
|
openapi: {
|
|
207
216
|
operationId: "createUser",
|
|
@@ -282,7 +291,7 @@ const admin = (options) => {
|
|
|
282
291
|
"/admin/list-users",
|
|
283
292
|
{
|
|
284
293
|
method: "GET",
|
|
285
|
-
use: [
|
|
294
|
+
use: [adminMiddleware],
|
|
286
295
|
query: zod.z.object({
|
|
287
296
|
searchValue: zod.z.string({
|
|
288
297
|
description: "The value to search for"
|
|
@@ -411,7 +420,7 @@ const admin = (options) => {
|
|
|
411
420
|
"/admin/list-user-sessions",
|
|
412
421
|
{
|
|
413
422
|
method: "POST",
|
|
414
|
-
use: [
|
|
423
|
+
use: [adminMiddleware],
|
|
415
424
|
body: zod.z.object({
|
|
416
425
|
userId: zod.z.string({
|
|
417
426
|
description: "The user id"
|
|
@@ -477,7 +486,7 @@ const admin = (options) => {
|
|
|
477
486
|
description: "The user id"
|
|
478
487
|
})
|
|
479
488
|
}),
|
|
480
|
-
use: [
|
|
489
|
+
use: [adminMiddleware],
|
|
481
490
|
metadata: {
|
|
482
491
|
openapi: {
|
|
483
492
|
operationId: "unbanUser",
|
|
@@ -552,7 +561,7 @@ const admin = (options) => {
|
|
|
552
561
|
description: "The number of seconds until the ban expires"
|
|
553
562
|
}).optional()
|
|
554
563
|
}),
|
|
555
|
-
use: [
|
|
564
|
+
use: [adminMiddleware],
|
|
556
565
|
metadata: {
|
|
557
566
|
openapi: {
|
|
558
567
|
operationId: "banUser",
|
|
@@ -622,7 +631,7 @@ const admin = (options) => {
|
|
|
622
631
|
description: "The user id"
|
|
623
632
|
})
|
|
624
633
|
}),
|
|
625
|
-
use: [
|
|
634
|
+
use: [adminMiddleware],
|
|
626
635
|
metadata: {
|
|
627
636
|
openapi: {
|
|
628
637
|
operationId: "impersonateUser",
|
|
@@ -763,7 +772,7 @@ const admin = (options) => {
|
|
|
763
772
|
description: "The session token"
|
|
764
773
|
})
|
|
765
774
|
}),
|
|
766
|
-
use: [
|
|
775
|
+
use: [adminMiddleware],
|
|
767
776
|
metadata: {
|
|
768
777
|
openapi: {
|
|
769
778
|
operationId: "revokeUserSession",
|
|
@@ -821,7 +830,7 @@ const admin = (options) => {
|
|
|
821
830
|
description: "The user id"
|
|
822
831
|
})
|
|
823
832
|
}),
|
|
824
|
-
use: [
|
|
833
|
+
use: [adminMiddleware],
|
|
825
834
|
metadata: {
|
|
826
835
|
openapi: {
|
|
827
836
|
operationId: "revokeUserSessions",
|
|
@@ -877,7 +886,7 @@ const admin = (options) => {
|
|
|
877
886
|
description: "The user id"
|
|
878
887
|
})
|
|
879
888
|
}),
|
|
880
|
-
use: [
|
|
889
|
+
use: [adminMiddleware],
|
|
881
890
|
metadata: {
|
|
882
891
|
openapi: {
|
|
883
892
|
operationId: "removeUser",
|
|
@@ -936,7 +945,7 @@ const admin = (options) => {
|
|
|
936
945
|
description: "The user id"
|
|
937
946
|
})
|
|
938
947
|
}),
|
|
939
|
-
use: [
|
|
948
|
+
use: [adminMiddleware],
|
|
940
949
|
metadata: {
|
|
941
950
|
openapi: {
|
|
942
951
|
operationId: "setUserPassword",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { APIError } from 'better-call';
|
|
3
|
-
import {
|
|
3
|
+
import { c as createAuthMiddleware, g as getSessionFromCtx, a as createAuthEndpoint } from './better-auth.npe3WWSD.mjs';
|
|
4
4
|
import { setSessionCookie, deleteSessionCookie } from '../cookies/index.mjs';
|
|
5
5
|
import { m as mergeSchema } from './better-auth.C24Bzw4w.mjs';
|
|
6
6
|
import './better-auth.8zoxzg-F.mjs';
|
|
@@ -8,7 +8,6 @@ import './better-auth.DH3YjMQH.mjs';
|
|
|
8
8
|
import 'defu';
|
|
9
9
|
import { g as getDate } from './better-auth.CW6D9eSx.mjs';
|
|
10
10
|
import { g as getEndpointResponse } from './better-auth.DQI8AD7d.mjs';
|
|
11
|
-
import { a as adminMiddleware } from './better-auth.Do0oI2pb.mjs';
|
|
12
11
|
import { defaultRoles } from '../plugins/admin/access/index.mjs';
|
|
13
12
|
|
|
14
13
|
const ADMIN_ERROR_CODES = {
|
|
@@ -45,8 +44,18 @@ const hasPermission = (input) => {
|
|
|
45
44
|
const admin = (options) => {
|
|
46
45
|
const opts = {
|
|
47
46
|
defaultRole: "user",
|
|
47
|
+
adminRoles: ["admin"],
|
|
48
48
|
...options
|
|
49
49
|
};
|
|
50
|
+
const adminMiddleware = createAuthMiddleware(async (ctx) => {
|
|
51
|
+
const session = await getSessionFromCtx(ctx);
|
|
52
|
+
if ((!session?.session || !opts.adminRoles.includes(session.user.role)) && !opts.adminUserIds?.includes(session?.user.id || "")) {
|
|
53
|
+
throw new APIError("UNAUTHORIZED");
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
session
|
|
57
|
+
};
|
|
58
|
+
});
|
|
50
59
|
return {
|
|
51
60
|
id: "admin",
|
|
52
61
|
init(ctx) {
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const betterCall = require('better-call');
|
|
4
|
-
const account = require('./better-auth.BzKRBwSF.cjs');
|
|
5
|
-
require('zod');
|
|
6
|
-
require('./better-auth.DiSjtgs9.cjs');
|
|
7
|
-
require('@better-auth/utils/base64');
|
|
8
|
-
require('@better-auth/utils/hmac');
|
|
9
|
-
require('./better-auth.CHyZMcYK.cjs');
|
|
10
|
-
require('./better-auth.GpOOav9x.cjs');
|
|
11
|
-
require('defu');
|
|
12
|
-
|
|
13
|
-
const adminMiddleware = account.createAuthMiddleware(async (ctx) => {
|
|
14
|
-
const session = await account.getSessionFromCtx(ctx);
|
|
15
|
-
if (!session?.session) {
|
|
16
|
-
throw new betterCall.APIError("UNAUTHORIZED");
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
session
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
exports.adminMiddleware = adminMiddleware;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { APIError } from 'better-call';
|
|
2
|
-
import { c as createAuthMiddleware, g as getSessionFromCtx } from './better-auth.npe3WWSD.mjs';
|
|
3
|
-
import 'zod';
|
|
4
|
-
import './better-auth.8zoxzg-F.mjs';
|
|
5
|
-
import '@better-auth/utils/base64';
|
|
6
|
-
import '@better-auth/utils/hmac';
|
|
7
|
-
import './better-auth.C24Bzw4w.mjs';
|
|
8
|
-
import './better-auth.DH3YjMQH.mjs';
|
|
9
|
-
import 'defu';
|
|
10
|
-
|
|
11
|
-
const adminMiddleware = createAuthMiddleware(async (ctx) => {
|
|
12
|
-
const session = await getSessionFromCtx(ctx);
|
|
13
|
-
if (!session?.session) {
|
|
14
|
-
throw new APIError("UNAUTHORIZED");
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
session
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export { adminMiddleware as a };
|