@xk2800/nextjs-template 0.7.2-beta.7 → 0.7.2-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/components/auth/forms/signup-form.tsx +3 -0
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +1 -1
- package/components/dashboard/admin/users/impersonation-tab.tsx +1 -1
- package/components/dashboard/layout/app-sidebar.tsx +7 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/layout/top-nav.tsx +14 -33
- package/components/dashboard/settings/activity-logs-card.tsx +1 -1
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +64 -13
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +25 -18
- package/dist/activity/queries.d.ts +25 -18
- package/dist/activity/queries.js +73 -20
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +15 -13
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +44 -13
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +7 -7
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +247 -224
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +262 -239
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +14 -23
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +54 -12
- package/dist/auth/helpers.d.ts +54 -12
- package/dist/auth/helpers.js +276 -242
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +68 -47
- package/dist/auth/index.d.ts +68 -47
- package/dist/auth/index.js +242 -221
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1215 -2527
- package/dist/auth-client/index.d.ts +1215 -2527
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-M6Y2XNJC.mjs → chunk-3BH6BVBQ.mjs} +16 -6
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-J5XRJ2GW.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/{chunk-J5XRJ2GW.mjs.map → chunk-DWLMCMXF.mjs.map} +1 -1
- package/dist/{chunk-AOSJUQQG.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/{chunk-AOSJUQQG.mjs.map → chunk-EXMUANQ3.mjs.map} +1 -1
- package/dist/{chunk-NOFQCVHC.mjs → chunk-IH6CMZIN.mjs} +195 -215
- package/dist/chunk-IH6CMZIN.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-TMANA7KL.mjs → chunk-NJBRKKLK.mjs} +9 -6
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-JRDMU6I2.mjs → chunk-QDUPSU5O.mjs} +3 -3
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-2BKXG4MG.mjs → chunk-S23GC776.mjs} +38 -27
- package/dist/chunk-S23GC776.mjs.map +1 -0
- package/dist/{chunk-CRDC62BU.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/{chunk-CRDC62BU.mjs.map → chunk-TIR7KHXL.mjs.map} +1 -1
- package/dist/{chunk-JSB36AY6.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +60 -11
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +13 -3
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +60 -11
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +12 -2
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +60 -11
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +3 -2
- package/dist/settings/queries.d.ts +3 -2
- package/dist/settings/queries.js +46 -12
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +24 -19
- package/dist/users/queries.d.ts +24 -19
- package/dist/users/queries.js +48 -13
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +8 -6
- package/dist/users/queries.mjs.map +1 -1
- package/lib/auth/client.ts +22 -2
- package/lib/utils/request-info.ts +7 -3
- package/package.json +65 -59
- package/scripts/check-deps.mjs +67 -0
- package/dist/chunk-2BKXG4MG.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-JRDMU6I2.mjs.map +0 -1
- package/dist/chunk-JSB36AY6.mjs.map +0 -1
- package/dist/chunk-M6Y2XNJC.mjs.map +0 -1
- package/dist/chunk-NOFQCVHC.mjs.map +0 -1
- package/dist/chunk-RLZ7F7ZY.mjs +0 -30
- package/dist/chunk-RLZ7F7ZY.mjs.map +0 -1
- package/dist/chunk-TMANA7KL.mjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { logActivity } from './chunk-
|
|
2
|
-
import { getClientIp, formatLocation, lookupGeoLocation, formatDeviceInfo, parseUserAgent, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-
|
|
3
|
-
import { getEffectiveAuthFlags } from './chunk-
|
|
4
|
-
import { getResend, EMAIL_FROM } from './chunk-
|
|
5
|
-
import { db } from './chunk-
|
|
6
|
-
import { users, passkeys, twoFactors, verifications, sessions, accounts, authThrottle } from './chunk-
|
|
7
|
-
import { config } from './chunk-
|
|
1
|
+
import { logActivity } from './chunk-ZOQHHFYA.mjs';
|
|
2
|
+
import { getClientIp, formatLocation, lookupGeoLocation, formatDeviceInfo, parseUserAgent, WINDOW_MS, isOverLimit, MAX_IP, RETENTION_MS } from './chunk-QDUPSU5O.mjs';
|
|
3
|
+
import { getEffectiveAuthFlags } from './chunk-NJBRKKLK.mjs';
|
|
4
|
+
import { getResend, EMAIL_FROM } from './chunk-TIR7KHXL.mjs';
|
|
5
|
+
import { db } from './chunk-LADVCLEQ.mjs';
|
|
6
|
+
import { users, passkeys, twoFactors, verifications, sessions, accounts, authThrottle } from './chunk-3BH6BVBQ.mjs';
|
|
7
|
+
import { config } from './chunk-DCPVEZS7.mjs';
|
|
8
8
|
import { __spreadValues, __spreadProps } from './chunk-3465SI5N.mjs';
|
|
9
9
|
import 'server-only';
|
|
10
10
|
import { betterAuth } from 'better-auth';
|
|
@@ -16,15 +16,25 @@ import { createAuthMiddleware, APIError, getSessionFromCtx } from 'better-auth/a
|
|
|
16
16
|
import { symmetricDecrypt } from 'better-auth/crypto';
|
|
17
17
|
import { passkey } from '@better-auth/passkey';
|
|
18
18
|
|
|
19
|
+
// node_modules/@better-auth/utils/dist/bytes.mjs
|
|
20
|
+
function toBufferSource(data) {
|
|
21
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
22
|
+
if (!ArrayBuffer.isView(data)) return data;
|
|
23
|
+
if (data.buffer instanceof ArrayBuffer) return data;
|
|
24
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();
|
|
25
|
+
}
|
|
26
|
+
function toUint8Array(data) {
|
|
27
|
+
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
28
|
+
return new Uint8Array(data);
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
// node_modules/@better-auth/utils/dist/base32.mjs
|
|
20
32
|
function getAlphabet(hex2) {
|
|
21
33
|
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
22
34
|
}
|
|
23
35
|
function createDecodeMap(alphabet) {
|
|
24
36
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
25
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
26
|
-
decodeMap.set(alphabet[i], i);
|
|
27
|
-
}
|
|
37
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
28
38
|
return decodeMap;
|
|
29
39
|
}
|
|
30
40
|
function base32Encode(data, alphabet, padding) {
|
|
@@ -39,9 +49,7 @@ function base32Encode(data, alphabet, padding) {
|
|
|
39
49
|
result += alphabet[buffer >> shift & 31];
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
|
-
if (shift > 0)
|
|
43
|
-
result += alphabet[buffer << 5 - shift & 31];
|
|
44
|
-
}
|
|
52
|
+
if (shift > 0) result += alphabet[buffer << 5 - shift & 31];
|
|
45
53
|
if (padding) {
|
|
46
54
|
const padCount = (8 - result.length % 8) % 8;
|
|
47
55
|
result += "=".repeat(padCount);
|
|
@@ -54,12 +62,9 @@ function base32Decode(data, alphabet) {
|
|
|
54
62
|
let buffer = 0;
|
|
55
63
|
let bitsCollected = 0;
|
|
56
64
|
for (const char of data) {
|
|
57
|
-
if (char === "=")
|
|
58
|
-
break;
|
|
65
|
+
if (char === "=") break;
|
|
59
66
|
const value = decodeMap.get(char);
|
|
60
|
-
if (value === void 0) {
|
|
61
|
-
throw new Error(`Invalid Base32 character: ${char}`);
|
|
62
|
-
}
|
|
67
|
+
if (value === void 0) throw new Error(`Invalid Base32 character: ${char}`);
|
|
63
68
|
buffer = buffer << 5 | value;
|
|
64
69
|
bitsCollected += 5;
|
|
65
70
|
while (bitsCollected >= 8) {
|
|
@@ -71,68 +76,34 @@ function base32Decode(data, alphabet) {
|
|
|
71
76
|
}
|
|
72
77
|
var base32 = {
|
|
73
78
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
* Encodes data into a Base32 string.
|
|
80
|
+
* @param data - The data to encode (ArrayBuffer, number-based TypedArray, or string).
|
|
81
|
+
* @param options - Encoding options.
|
|
82
|
+
* @returns The Base32 encoded string.
|
|
83
|
+
*/
|
|
79
84
|
encode(data, options = {}) {
|
|
80
85
|
var _a;
|
|
81
86
|
const alphabet = getAlphabet();
|
|
82
|
-
|
|
83
|
-
return base32Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
87
|
+
return base32Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
84
88
|
},
|
|
85
89
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
* Decodes a Base32 string into a Uint8Array.
|
|
91
|
+
* @param data - The Base32 encoded string or ArrayBuffer/TypedArray.
|
|
92
|
+
* @returns The decoded Uint8Array.
|
|
93
|
+
*/
|
|
90
94
|
decode(data) {
|
|
91
|
-
if (typeof data !== "string")
|
|
92
|
-
data = new TextDecoder().decode(data);
|
|
93
|
-
}
|
|
95
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
94
96
|
const alphabet = getAlphabet();
|
|
95
97
|
return base32Decode(data, alphabet);
|
|
96
98
|
}
|
|
97
99
|
};
|
|
98
100
|
|
|
99
|
-
// node_modules/@better-auth/utils/dist/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
if (data.byteLength === 0) {
|
|
107
|
-
return "";
|
|
108
|
-
}
|
|
109
|
-
const buffer = new Uint8Array(data);
|
|
110
|
-
let result = "";
|
|
111
|
-
for (const byte of buffer) {
|
|
112
|
-
result += byte.toString(16).padStart(2, "0");
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
},
|
|
116
|
-
decode: (data) => {
|
|
117
|
-
if (!data) {
|
|
118
|
-
return "";
|
|
119
|
-
}
|
|
120
|
-
if (typeof data === "string") {
|
|
121
|
-
if (data.length % 2 !== 0) {
|
|
122
|
-
throw new Error("Invalid hexadecimal string");
|
|
123
|
-
}
|
|
124
|
-
if (!new RegExp(`^[${hexadecimal}]+$`).test(data)) {
|
|
125
|
-
throw new Error("Invalid hexadecimal string");
|
|
126
|
-
}
|
|
127
|
-
const result = new Uint8Array(data.length / 2);
|
|
128
|
-
for (let i = 0; i < data.length; i += 2) {
|
|
129
|
-
result[i / 2] = parseInt(data.slice(i, i + 2), 16);
|
|
130
|
-
}
|
|
131
|
-
return new TextDecoder().decode(result);
|
|
132
|
-
}
|
|
133
|
-
return new TextDecoder().decode(data);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
101
|
+
// node_modules/@better-auth/utils/dist/index.mjs
|
|
102
|
+
function getWebcryptoSubtle() {
|
|
103
|
+
const cr = typeof globalThis !== "undefined" && globalThis.crypto;
|
|
104
|
+
if (cr && typeof cr.subtle === "object" && cr.subtle != null) return cr.subtle;
|
|
105
|
+
throw new Error("crypto.subtle must be defined");
|
|
106
|
+
}
|
|
136
107
|
|
|
137
108
|
// node_modules/@better-auth/utils/dist/base64.mjs
|
|
138
109
|
function getAlphabet2(urlSafe) {
|
|
@@ -150,9 +121,7 @@ function base64Encode(data, alphabet, padding) {
|
|
|
150
121
|
result += alphabet[buffer >> shift & 63];
|
|
151
122
|
}
|
|
152
123
|
}
|
|
153
|
-
if (shift > 0)
|
|
154
|
-
result += alphabet[buffer << 6 - shift & 63];
|
|
155
|
-
}
|
|
124
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
156
125
|
if (padding) {
|
|
157
126
|
const padCount = (4 - result.length % 4) % 4;
|
|
158
127
|
result += "=".repeat(padCount);
|
|
@@ -161,19 +130,14 @@ function base64Encode(data, alphabet, padding) {
|
|
|
161
130
|
}
|
|
162
131
|
function base64Decode(data, alphabet) {
|
|
163
132
|
const decodeMap = /* @__PURE__ */ new Map();
|
|
164
|
-
for (let i = 0; i < alphabet.length; i++)
|
|
165
|
-
decodeMap.set(alphabet[i], i);
|
|
166
|
-
}
|
|
133
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
167
134
|
const result = [];
|
|
168
135
|
let buffer = 0;
|
|
169
136
|
let bitsCollected = 0;
|
|
170
137
|
for (const char of data) {
|
|
171
|
-
if (char === "=")
|
|
172
|
-
break;
|
|
138
|
+
if (char === "=") break;
|
|
173
139
|
const value = decodeMap.get(char);
|
|
174
|
-
if (value === void 0) {
|
|
175
|
-
throw new Error(`Invalid Base64 character: ${char}`);
|
|
176
|
-
}
|
|
140
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
177
141
|
buffer = buffer << 6 | value;
|
|
178
142
|
bitsCollected += 6;
|
|
179
143
|
if (bitsCollected >= 8) {
|
|
@@ -187,15 +151,11 @@ var base64 = {
|
|
|
187
151
|
encode(data, options = {}) {
|
|
188
152
|
var _a;
|
|
189
153
|
const alphabet = getAlphabet2(false);
|
|
190
|
-
|
|
191
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
154
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
192
155
|
},
|
|
193
156
|
decode(data) {
|
|
194
|
-
if (typeof data !== "string")
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
const urlSafe = data.includes("-") || data.includes("_");
|
|
198
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
157
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
158
|
+
const alphabet = getAlphabet2(data.includes("-") || data.includes("_"));
|
|
199
159
|
return base64Decode(data, alphabet);
|
|
200
160
|
}
|
|
201
161
|
};
|
|
@@ -203,152 +163,142 @@ var base64Url = {
|
|
|
203
163
|
encode(data, options = {}) {
|
|
204
164
|
var _a;
|
|
205
165
|
const alphabet = getAlphabet2(true);
|
|
206
|
-
|
|
207
|
-
return base64Encode(buffer, alphabet, (_a = options.padding) != null ? _a : true);
|
|
166
|
+
return base64Encode(toUint8Array(data), alphabet, (_a = options.padding) != null ? _a : true);
|
|
208
167
|
},
|
|
209
168
|
decode(data) {
|
|
210
|
-
|
|
211
|
-
const alphabet = getAlphabet2(urlSafe);
|
|
212
|
-
return base64Decode(data, alphabet);
|
|
169
|
+
return base64Decode(data, getAlphabet2(data.includes("-") || data.includes("_")));
|
|
213
170
|
}
|
|
214
171
|
};
|
|
215
172
|
|
|
216
|
-
// node_modules/@
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
173
|
+
// node_modules/@noble/hashes/utils.js
|
|
174
|
+
var hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function"
|
|
177
|
+
))();
|
|
178
|
+
function asciiToBase16(ch) {
|
|
179
|
+
return ch >= 48 && ch <= 57 ? ch - 48 : ch >= 65 && ch <= 70 ? ch - (65 - 10) : ch >= 97 && ch <= 102 ? ch - (97 - 10) : void 0;
|
|
180
|
+
}
|
|
181
|
+
function hexToBytes(hex2) {
|
|
182
|
+
if (typeof hex2 !== "string")
|
|
183
|
+
throw new TypeError("hex string expected, got " + typeof hex2);
|
|
184
|
+
if (hasHexBuiltin) {
|
|
185
|
+
try {
|
|
186
|
+
return Uint8Array.fromHex(hex2);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error instanceof SyntaxError)
|
|
189
|
+
throw new RangeError(error.message);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const hl = hex2.length;
|
|
194
|
+
const al = hl / 2;
|
|
195
|
+
if (hl % 2)
|
|
196
|
+
throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
197
|
+
const array = new Uint8Array(al);
|
|
198
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
199
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
200
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
201
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
202
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
203
|
+
throw new RangeError('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
204
|
+
}
|
|
205
|
+
array[ai] = n1 * 16 + n2;
|
|
206
|
+
}
|
|
207
|
+
return array;
|
|
222
208
|
}
|
|
223
209
|
|
|
210
|
+
// node_modules/@better-auth/utils/dist/hex.mjs
|
|
211
|
+
var toBytes = (data) => hexToBytes(data);
|
|
212
|
+
var hex = {
|
|
213
|
+
encode: (data) => {
|
|
214
|
+
const buffer = toUint8Array(data);
|
|
215
|
+
if (buffer.byteLength === 0) return "";
|
|
216
|
+
let result = "";
|
|
217
|
+
for (const byte of buffer) result += byte.toString(16).padStart(2, "0");
|
|
218
|
+
return result;
|
|
219
|
+
},
|
|
220
|
+
decode: (data) => {
|
|
221
|
+
if (!data) return "";
|
|
222
|
+
if (typeof data === "string") return new TextDecoder().decode(toBytes(data));
|
|
223
|
+
return new TextDecoder().decode(data);
|
|
224
|
+
},
|
|
225
|
+
toBytes
|
|
226
|
+
};
|
|
227
|
+
|
|
224
228
|
// node_modules/@better-auth/utils/dist/hmac.mjs
|
|
225
229
|
var createHMAC = (algorithm = "SHA-256", encoding = "none") => {
|
|
226
|
-
const
|
|
230
|
+
const hmac2 = {
|
|
227
231
|
importKey: async (key, keyUsage) => {
|
|
228
|
-
return getWebcryptoSubtle().importKey(
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
false,
|
|
233
|
-
[keyUsage]
|
|
234
|
-
);
|
|
232
|
+
return getWebcryptoSubtle().importKey("raw", toBufferSource(key), {
|
|
233
|
+
name: "HMAC",
|
|
234
|
+
hash: { name: algorithm }
|
|
235
|
+
}, false, [keyUsage]);
|
|
235
236
|
},
|
|
236
237
|
sign: async (hmacKey, data) => {
|
|
237
|
-
if (typeof hmacKey === "string")
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
hmacKey,
|
|
243
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
244
|
-
);
|
|
245
|
-
if (encoding === "hex") {
|
|
246
|
-
return hex.encode(signature);
|
|
247
|
-
}
|
|
248
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
249
|
-
return base64Url.encode(signature, {
|
|
250
|
-
padding: encoding !== "base64urlnopad"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
238
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "sign");
|
|
239
|
+
const signature = await getWebcryptoSubtle().sign("HMAC", hmacKey, toBufferSource(data));
|
|
240
|
+
if (encoding === "hex") return hex.encode(signature);
|
|
241
|
+
if (encoding === "base64") return base64.encode(signature);
|
|
242
|
+
if (encoding === "base64url" || encoding === "base64urlnopad") return base64Url.encode(signature, { padding: encoding !== "base64urlnopad" });
|
|
253
243
|
return signature;
|
|
254
244
|
},
|
|
255
245
|
verify: async (hmacKey, data, signature) => {
|
|
256
|
-
if (typeof hmacKey === "string")
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
signature = hex.decode(signature);
|
|
261
|
-
}
|
|
262
|
-
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") {
|
|
263
|
-
signature = await base64.decode(signature);
|
|
264
|
-
}
|
|
265
|
-
return getWebcryptoSubtle().verify(
|
|
266
|
-
"HMAC",
|
|
267
|
-
hmacKey,
|
|
268
|
-
typeof signature === "string" ? new TextEncoder().encode(signature) : signature,
|
|
269
|
-
typeof data === "string" ? new TextEncoder().encode(data) : data
|
|
270
|
-
);
|
|
246
|
+
if (typeof hmacKey === "string") hmacKey = await hmac2.importKey(hmacKey, "verify");
|
|
247
|
+
if (encoding === "hex") signature = typeof signature === "string" ? hex.toBytes(signature) : signature;
|
|
248
|
+
if (encoding === "base64" || encoding === "base64url" || encoding === "base64urlnopad") signature = await base64.decode(signature);
|
|
249
|
+
return getWebcryptoSubtle().verify("HMAC", hmacKey, toBufferSource(signature), toBufferSource(data));
|
|
271
250
|
}
|
|
272
251
|
};
|
|
273
|
-
return
|
|
252
|
+
return hmac2;
|
|
274
253
|
};
|
|
275
254
|
|
|
276
255
|
// node_modules/@better-auth/utils/dist/otp.mjs
|
|
277
256
|
var defaultPeriod = 30;
|
|
278
257
|
var defaultDigits = 6;
|
|
258
|
+
var hmac = createHMAC("SHA-1");
|
|
279
259
|
function constantTimeEqualOTP(input, expected) {
|
|
280
260
|
let difference = input.length ^ expected.length;
|
|
281
|
-
for (let i = 0; i < expected.length; i++)
|
|
282
|
-
difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
283
|
-
}
|
|
261
|
+
for (let i = 0; i < expected.length; i++) difference |= input.charCodeAt(i) ^ expected.charCodeAt(i);
|
|
284
262
|
return difference === 0;
|
|
285
263
|
}
|
|
286
|
-
async function generateHOTP(
|
|
287
|
-
counter,
|
|
288
|
-
digits,
|
|
289
|
-
hash = "SHA-1"
|
|
290
|
-
}) {
|
|
264
|
+
async function generateHOTP(key, { counter, digits }) {
|
|
291
265
|
const _digits = digits != null ? digits : defaultDigits;
|
|
292
|
-
if (_digits < 1 || _digits > 8)
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
const buffer = new ArrayBuffer(8);
|
|
266
|
+
if (_digits < 1 || _digits > 8) throw new TypeError("Digits must be between 1 and 8");
|
|
267
|
+
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
296
268
|
new DataView(buffer).setBigUint64(0, BigInt(counter), false);
|
|
297
269
|
const bytes = new Uint8Array(buffer);
|
|
298
|
-
const
|
|
270
|
+
const signature = await hmac.sign(key, bytes);
|
|
271
|
+
const hmacResult = new Uint8Array(signature);
|
|
299
272
|
const offset = hmacResult[hmacResult.length - 1] & 15;
|
|
300
|
-
|
|
301
|
-
const otp = truncated % 10 ** _digits;
|
|
302
|
-
return otp.toString().padStart(_digits, "0");
|
|
273
|
+
return (((hmacResult[offset] & 127) << 24 | (hmacResult[offset + 1] & 255) << 16 | (hmacResult[offset + 2] & 255) << 8 | hmacResult[offset + 3] & 255) % 10 ** _digits).toString().padStart(_digits, "0");
|
|
303
274
|
}
|
|
304
|
-
async function generateTOTP(
|
|
275
|
+
async function generateTOTP(key, options) {
|
|
305
276
|
var _a, _b;
|
|
306
277
|
const digits = (_a = options == null ? void 0 : options.digits) != null ? _a : defaultDigits;
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
278
|
+
const milliseconds = ((_b = options == null ? void 0 : options.period) != null ? _b : defaultPeriod) * 1e3;
|
|
279
|
+
return await generateHOTP(key, {
|
|
280
|
+
counter: Math.floor(Date.now() / milliseconds),
|
|
281
|
+
digits
|
|
282
|
+
});
|
|
311
283
|
}
|
|
312
|
-
async function verifyTOTP(otp, {
|
|
313
|
-
window = 1,
|
|
314
|
-
digits = defaultDigits,
|
|
315
|
-
secret,
|
|
316
|
-
period = defaultPeriod
|
|
317
|
-
}) {
|
|
284
|
+
async function verifyTOTP(otp, { window = 1, digits = defaultDigits, key, period = defaultPeriod }) {
|
|
318
285
|
const milliseconds = period * 1e3;
|
|
319
286
|
const counter = Math.floor(Date.now() / milliseconds);
|
|
320
287
|
let matched = false;
|
|
321
|
-
for (let i = -window; i <= window; i++) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
});
|
|
326
|
-
matched = constantTimeEqualOTP(otp, generatedOTP) || matched;
|
|
327
|
-
}
|
|
288
|
+
for (let i = -window; i <= window; i++) matched = constantTimeEqualOTP(otp, await generateHOTP(key, {
|
|
289
|
+
counter: counter + i,
|
|
290
|
+
digits
|
|
291
|
+
})) || matched;
|
|
328
292
|
return matched;
|
|
329
293
|
}
|
|
330
|
-
function generateQRCode({
|
|
331
|
-
issuer
|
|
332
|
-
account,
|
|
333
|
-
secret,
|
|
334
|
-
digits = defaultDigits,
|
|
335
|
-
period = defaultPeriod
|
|
336
|
-
}) {
|
|
337
|
-
const encodedIssuer = encodeURIComponent(issuer);
|
|
338
|
-
const encodedAccountName = encodeURIComponent(account);
|
|
339
|
-
const baseURI = `otpauth://totp/${encodedIssuer}:${encodedAccountName}`;
|
|
294
|
+
function generateQRCode({ issuer, account, secret, digits = defaultDigits, period = defaultPeriod }) {
|
|
295
|
+
const baseURI = `otpauth://totp/${encodeURIComponent(issuer)}:${encodeURIComponent(account)}`;
|
|
340
296
|
const params = new URLSearchParams({
|
|
341
|
-
secret: base32.encode(secret, {
|
|
342
|
-
padding: false
|
|
343
|
-
}),
|
|
297
|
+
secret: base32.encode(secret, { padding: false }),
|
|
344
298
|
issuer
|
|
345
299
|
});
|
|
346
|
-
if (digits !== void 0)
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
if (period !== void 0) {
|
|
350
|
-
params.set("period", period.toString());
|
|
351
|
-
}
|
|
300
|
+
if (digits !== void 0) params.set("digits", digits.toString());
|
|
301
|
+
if (period !== void 0) params.set("period", period.toString());
|
|
352
302
|
return `${baseURI}?${params.toString()}`;
|
|
353
303
|
}
|
|
354
304
|
var createOTP = (secret, opts) => {
|
|
@@ -356,10 +306,34 @@ var createOTP = (secret, opts) => {
|
|
|
356
306
|
const digits = (_a = void 0 ) != null ? _a : defaultDigits;
|
|
357
307
|
const period = (_b = void 0 ) != null ? _b : defaultPeriod;
|
|
358
308
|
return {
|
|
359
|
-
hotp: (counter) =>
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
309
|
+
hotp: async (counter) => {
|
|
310
|
+
return generateHOTP(await hmac.importKey(secret, "sign"), {
|
|
311
|
+
counter,
|
|
312
|
+
digits
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
totp: async () => {
|
|
316
|
+
return generateTOTP(await hmac.importKey(secret, "sign"), {
|
|
317
|
+
digits,
|
|
318
|
+
period
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
verify: async (otp, options) => {
|
|
322
|
+
return verifyTOTP(otp, __spreadValues({
|
|
323
|
+
key: await hmac.importKey(secret, "sign"),
|
|
324
|
+
digits,
|
|
325
|
+
period
|
|
326
|
+
}, options));
|
|
327
|
+
},
|
|
328
|
+
url: (issuer, account) => {
|
|
329
|
+
return generateQRCode({
|
|
330
|
+
issuer,
|
|
331
|
+
account,
|
|
332
|
+
secret,
|
|
333
|
+
digits,
|
|
334
|
+
period
|
|
335
|
+
});
|
|
336
|
+
}
|
|
363
337
|
};
|
|
364
338
|
};
|
|
365
339
|
|
|
@@ -423,6 +397,16 @@ function twoFactorPlugins(baseURL, { issuer, passwordless = false, challengeAfte
|
|
|
423
397
|
// lib/security/cookie-names.ts
|
|
424
398
|
var LOGIN_REFERRER_COOKIE = "login_referrer";
|
|
425
399
|
var DEVICE_FINGERPRINT_HEADER = "x-device-fingerprint";
|
|
400
|
+
|
|
401
|
+
// lib/auth/base-url.ts
|
|
402
|
+
function getBaseUrl() {
|
|
403
|
+
const url = process.env.BETTER_AUTH_URL || process.env.NEXTAUTH_URL || process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
|
|
404
|
+
return url.replace(/\/+$/, "");
|
|
405
|
+
}
|
|
406
|
+
function otherActiveAdminExists(excludeIds) {
|
|
407
|
+
const ids = sql.join(excludeIds.map((id) => sql`${id}`), sql`, `);
|
|
408
|
+
return sql`(select count(*) from (select ${users.id} as id from ${users} where ${users.role} = 'admin' and ${users.banned} = false for update) a where a.id not in (${ids})) > 0`;
|
|
409
|
+
}
|
|
426
410
|
async function isDeviceThrottled(fingerprint, max) {
|
|
427
411
|
try {
|
|
428
412
|
const [row] = await db.select({ count: authThrottle.count, windowStart: authThrottle.windowStart }).from(authThrottle).where(eq(authThrottle.fingerprint, fingerprint)).limit(1);
|
|
@@ -446,8 +430,10 @@ async function recordDeviceAttempt(fingerprint, meta) {
|
|
|
446
430
|
await db.insert(authThrottle).values(__spreadValues({ fingerprint, count: 1, windowStart: now }, seen)).onConflictDoUpdate({
|
|
447
431
|
target: authThrottle.fingerprint,
|
|
448
432
|
set: __spreadValues({
|
|
449
|
-
|
|
450
|
-
|
|
433
|
+
// ISO strings, not Dates: pg sends a raw Date as server-local time, which a
|
|
434
|
+
// tz-less `timestamp` column (stored as UTC) misreads on any non-UTC host.
|
|
435
|
+
count: sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then 1 else ${authThrottle.count} + 1 end`,
|
|
436
|
+
windowStart: sql`case when ${authThrottle.windowStart} < ${cutoff.toISOString()} then ${now.toISOString()} else ${authThrottle.windowStart} end`
|
|
451
437
|
}, seen)
|
|
452
438
|
});
|
|
453
439
|
} catch (error) {
|
|
@@ -466,13 +452,6 @@ async function pruneStaleRows(now = /* @__PURE__ */ new Date()) {
|
|
|
466
452
|
console.error("auth-throttle prune failed", error);
|
|
467
453
|
}
|
|
468
454
|
}
|
|
469
|
-
async function clearDeviceThrottle(fingerprint) {
|
|
470
|
-
try {
|
|
471
|
-
await db.delete(authThrottle).where(eq(authThrottle.fingerprint, fingerprint));
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error("auth-throttle clear failed", error);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
455
|
|
|
477
456
|
// server/auth.ts
|
|
478
457
|
async function logFailedLogin(ctx, log) {
|
|
@@ -521,7 +500,7 @@ async function notifyPasskeyChange(ctx, action, log) {
|
|
|
521
500
|
location: formatLocation(lookupGeoLocation(ip)),
|
|
522
501
|
ipAddress: ip || "Unknown",
|
|
523
502
|
when: (/* @__PURE__ */ new Date()).toUTCString(),
|
|
524
|
-
manageUrl: `${
|
|
503
|
+
manageUrl: `${getBaseUrl()}/dashboard/settings`
|
|
525
504
|
})
|
|
526
505
|
});
|
|
527
506
|
} catch (error) {
|
|
@@ -596,7 +575,7 @@ function createAuth(overrides = {}) {
|
|
|
596
575
|
"No auth provider is enabled \u2014 every social provider is off and emailAndPassword.enabled is false. Enable AUTH_ENABLE_GOOGLE / AUTH_ENABLE_EMAIL_PASSWORD, or pass your own provider via createAuth({ socialProviders: {...} })."
|
|
597
576
|
);
|
|
598
577
|
}
|
|
599
|
-
const baseURL =
|
|
578
|
+
const baseURL = getBaseUrl();
|
|
600
579
|
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
601
580
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
602
581
|
issuer: config.APP_NAME,
|
|
@@ -730,7 +709,7 @@ function createAuth(overrides = {}) {
|
|
|
730
709
|
// available together.
|
|
731
710
|
hooks: {
|
|
732
711
|
before: createAuthMiddleware(async (ctx) => {
|
|
733
|
-
var _a2, _b2, _c2, _d2;
|
|
712
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
734
713
|
if (ctx.path === "/sign-in/email" || ctx.path === "/sign-up/email") {
|
|
735
714
|
const fingerprint = (_a2 = ctx.headers) == null ? void 0 : _a2.get(DEVICE_FINGERPRINT_HEADER);
|
|
736
715
|
const ip = getClientIp(ctx.headers);
|
|
@@ -764,6 +743,9 @@ function createAuth(overrides = {}) {
|
|
|
764
743
|
}
|
|
765
744
|
return;
|
|
766
745
|
}
|
|
746
|
+
if (ctx.request && ((_c2 = ctx.path) == null ? void 0 : _c2.startsWith("/admin/")) && ctx.path !== "/admin/impersonate-user" && ctx.path !== "/admin/stop-impersonating") {
|
|
747
|
+
throw new APIError("FORBIDDEN", { message: "Use the dashboard to manage users." });
|
|
748
|
+
}
|
|
767
749
|
if (ctx.path === "/admin/impersonate-user" && overrides.impersonation === false) {
|
|
768
750
|
throw new APIError("FORBIDDEN", { message: "Impersonation is turned off." });
|
|
769
751
|
}
|
|
@@ -774,8 +756,8 @@ function createAuth(overrides = {}) {
|
|
|
774
756
|
throw new APIError("FORBIDDEN", { message: "Stop impersonating before deleting an account." });
|
|
775
757
|
}
|
|
776
758
|
if (current2.user.role === "admin") {
|
|
777
|
-
const [
|
|
778
|
-
if (
|
|
759
|
+
const [other] = await db.select({ n: sql`1` }).from(users).where(otherActiveAdminExists([current2.user.id])).limit(1);
|
|
760
|
+
if (!other) {
|
|
779
761
|
throw new APIError("FORBIDDEN", { message: "You're the only admin. Promote another user to admin first." });
|
|
780
762
|
}
|
|
781
763
|
}
|
|
@@ -788,7 +770,7 @@ function createAuth(overrides = {}) {
|
|
|
788
770
|
await log({
|
|
789
771
|
userId: current.session.impersonatedBy,
|
|
790
772
|
action: "impersonation_stopped",
|
|
791
|
-
description: `Admin stopped impersonating ${(
|
|
773
|
+
description: `Admin stopped impersonating ${(_e2 = (_d2 = target[0]) == null ? void 0 : _d2.email) != null ? _e2 : current.session.userId}`,
|
|
792
774
|
metadata: { impersonatedUserId: current.session.userId }
|
|
793
775
|
});
|
|
794
776
|
}
|
|
@@ -824,8 +806,6 @@ function createAuth(overrides = {}) {
|
|
|
824
806
|
if (failed) {
|
|
825
807
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
826
808
|
await logFailedLogin(ctx, log);
|
|
827
|
-
} else {
|
|
828
|
-
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
829
809
|
}
|
|
830
810
|
})
|
|
831
811
|
},
|
|
@@ -907,6 +887,6 @@ var auth = new Proxy({}, {
|
|
|
907
887
|
}
|
|
908
888
|
});
|
|
909
889
|
|
|
910
|
-
export { auth, createAuth };
|
|
911
|
-
//# sourceMappingURL=chunk-
|
|
912
|
-
//# sourceMappingURL=chunk-
|
|
890
|
+
export { auth, createAuth, getBaseUrl };
|
|
891
|
+
//# sourceMappingURL=chunk-IH6CMZIN.mjs.map
|
|
892
|
+
//# sourceMappingURL=chunk-IH6CMZIN.mjs.map
|