@xk2800/nextjs-template 0.7.1-beta.17 → 0.7.1-beta.18
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/components/dashboard/admin/adminUsersTable.tsx +25 -12
- package/dist/activity/logger.d.mts +3 -1
- package/dist/activity/logger.d.ts +3 -1
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +1 -1
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/api/feedback.js +20 -18
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +2 -2
- package/dist/api/marketing.js +20 -18
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +3 -3
- package/dist/auth/helpers.d.mts +3 -3
- package/dist/auth/helpers.d.ts +3 -3
- package/dist/auth/helpers.js +20 -18
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +3 -3
- package/dist/auth/index.d.mts +9 -2
- package/dist/auth/index.d.ts +9 -2
- package/dist/auth/index.js +20 -18
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +2 -2
- package/dist/auth-client/index.d.mts +16 -16
- package/dist/auth-client/index.d.ts +16 -16
- package/dist/{chunk-BVCGLJYX.mjs → chunk-3BVXDGVH.mjs} +3 -3
- package/dist/{chunk-BVCGLJYX.mjs.map → chunk-3BVXDGVH.mjs.map} +1 -1
- package/dist/{chunk-QMGZKVBI.mjs → chunk-BZ6BJNYZ.mjs} +23 -21
- package/dist/chunk-BZ6BJNYZ.mjs.map +1 -0
- package/dist/{chunk-PSHG3WHD.mjs → chunk-KLQOKDIL.mjs} +2 -2
- package/dist/chunk-KLQOKDIL.mjs.map +1 -0
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/{schema-DIGqiX6c.d.mts → schema-B_3Oe9DD.d.mts} +1 -1
- package/dist/{schema-DIGqiX6c.d.ts → schema-B_3Oe9DD.d.ts} +1 -1
- package/dist/settings/queries.d.mts +1 -1
- package/dist/settings/queries.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-PSHG3WHD.mjs.map +0 -1
- package/dist/chunk-QMGZKVBI.mjs.map +0 -1
package/dist/auth/helpers.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { getCurrentSession, hasRole, normalizeCallbackUrl, requireAuth, requireRole } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { getCurrentSession, hasRole, normalizeCallbackUrl, requireAuth, requireRole } from '../chunk-3BVXDGVH.mjs';
|
|
2
|
+
import '../chunk-BZ6BJNYZ.mjs';
|
|
3
|
+
import '../chunk-KLQOKDIL.mjs';
|
|
4
4
|
import '../chunk-6OAHCEDJ.mjs';
|
|
5
5
|
import '../chunk-2BML32KG.mjs';
|
|
6
6
|
import '../chunk-OVKVD2HH.mjs';
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -7,6 +7,7 @@ import * as better_call from 'better-call';
|
|
|
7
7
|
import * as better_auth from 'better-auth';
|
|
8
8
|
import { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
|
|
9
9
|
import { createAuthMiddleware } from 'better-auth/api';
|
|
10
|
+
import { ActivityLogger } from '../activity/logger.mjs';
|
|
10
11
|
|
|
11
12
|
type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
|
|
12
13
|
type DatabaseHooks = NonNullable<BetterAuthOptions["databaseHooks"]>;
|
|
@@ -53,6 +54,12 @@ type AuthOverrides = {
|
|
|
53
54
|
impersonation?: boolean;
|
|
54
55
|
/** Self-service "Delete account" (better-auth's /delete-user). Default true. */
|
|
55
56
|
deleteUser?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Writes the package's auth activity entries (login, failed login, passkey added /
|
|
59
|
+
* removed, impersonation) instead of its own logger. Use it when your activity table
|
|
60
|
+
* needs your own connection, e.g. it has row-level security the package's `db` can't pass.
|
|
61
|
+
*/
|
|
62
|
+
logActivity?: ActivityLogger;
|
|
56
63
|
};
|
|
57
64
|
declare function createAuth(overrides?: AuthOverrides): better_auth.Auth<{
|
|
58
65
|
database: (options: BetterAuthOptions) => better_auth.DBAdapter<BetterAuthOptions>;
|
|
@@ -954,7 +961,7 @@ declare function createAuth(overrides?: AuthOverrides): better_auth.Auth<{
|
|
|
954
961
|
$Infer: {
|
|
955
962
|
body: {
|
|
956
963
|
permissions: {
|
|
957
|
-
readonly user?: ("
|
|
964
|
+
readonly user?: ("create" | "update" | "delete" | "set-role" | "list" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
958
965
|
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
959
966
|
};
|
|
960
967
|
} & {
|
|
@@ -3282,7 +3289,7 @@ declare const auth: better_auth.Auth<{
|
|
|
3282
3289
|
$Infer: {
|
|
3283
3290
|
body: {
|
|
3284
3291
|
permissions: {
|
|
3285
|
-
readonly user?: ("
|
|
3292
|
+
readonly user?: ("create" | "update" | "delete" | "set-role" | "list" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3286
3293
|
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3287
3294
|
};
|
|
3288
3295
|
} & {
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as better_call from 'better-call';
|
|
|
7
7
|
import * as better_auth from 'better-auth';
|
|
8
8
|
import { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
|
|
9
9
|
import { createAuthMiddleware } from 'better-auth/api';
|
|
10
|
+
import { ActivityLogger } from '../activity/logger.js';
|
|
10
11
|
|
|
11
12
|
type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
|
|
12
13
|
type DatabaseHooks = NonNullable<BetterAuthOptions["databaseHooks"]>;
|
|
@@ -53,6 +54,12 @@ type AuthOverrides = {
|
|
|
53
54
|
impersonation?: boolean;
|
|
54
55
|
/** Self-service "Delete account" (better-auth's /delete-user). Default true. */
|
|
55
56
|
deleteUser?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Writes the package's auth activity entries (login, failed login, passkey added /
|
|
59
|
+
* removed, impersonation) instead of its own logger. Use it when your activity table
|
|
60
|
+
* needs your own connection, e.g. it has row-level security the package's `db` can't pass.
|
|
61
|
+
*/
|
|
62
|
+
logActivity?: ActivityLogger;
|
|
56
63
|
};
|
|
57
64
|
declare function createAuth(overrides?: AuthOverrides): better_auth.Auth<{
|
|
58
65
|
database: (options: BetterAuthOptions) => better_auth.DBAdapter<BetterAuthOptions>;
|
|
@@ -954,7 +961,7 @@ declare function createAuth(overrides?: AuthOverrides): better_auth.Auth<{
|
|
|
954
961
|
$Infer: {
|
|
955
962
|
body: {
|
|
956
963
|
permissions: {
|
|
957
|
-
readonly user?: ("
|
|
964
|
+
readonly user?: ("create" | "update" | "delete" | "set-role" | "list" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
958
965
|
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
959
966
|
};
|
|
960
967
|
} & {
|
|
@@ -3282,7 +3289,7 @@ declare const auth: better_auth.Auth<{
|
|
|
3282
3289
|
$Infer: {
|
|
3283
3290
|
body: {
|
|
3284
3291
|
permissions: {
|
|
3285
|
-
readonly user?: ("
|
|
3292
|
+
readonly user?: ("create" | "update" | "delete" | "set-role" | "list" | "ban" | "impersonate" | "impersonate-admins" | "set-password" | "set-email" | "get")[] | undefined;
|
|
3286
3293
|
readonly session?: ("delete" | "list" | "revoke")[] | undefined;
|
|
3287
3294
|
};
|
|
3288
3295
|
} & {
|
package/dist/auth/index.js
CHANGED
|
@@ -1122,7 +1122,7 @@ async function getResend() {
|
|
|
1122
1122
|
config.RESEND_BROADCAST_API_KEY || config.RESEND_API_KEY;
|
|
1123
1123
|
|
|
1124
1124
|
// server/auth.ts
|
|
1125
|
-
async function logFailedLogin(ctx) {
|
|
1125
|
+
async function logFailedLogin(ctx, log) {
|
|
1126
1126
|
var _a, _b, _c;
|
|
1127
1127
|
try {
|
|
1128
1128
|
const raw = (_a = ctx.body) == null ? void 0 : _a.email;
|
|
@@ -1130,7 +1130,7 @@ async function logFailedLogin(ctx) {
|
|
|
1130
1130
|
if (!email) return;
|
|
1131
1131
|
const [user] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.email, email)).limit(1);
|
|
1132
1132
|
if (!user) return;
|
|
1133
|
-
await
|
|
1133
|
+
await log({
|
|
1134
1134
|
userId: user.id,
|
|
1135
1135
|
action: "login_failed",
|
|
1136
1136
|
description: "Failed login attempt",
|
|
@@ -1141,14 +1141,14 @@ async function logFailedLogin(ctx) {
|
|
|
1141
1141
|
console.error("Failed to log login_failed activity", error);
|
|
1142
1142
|
}
|
|
1143
1143
|
}
|
|
1144
|
-
async function notifyPasskeyChange(ctx, action) {
|
|
1144
|
+
async function notifyPasskeyChange(ctx, action, log) {
|
|
1145
1145
|
var _a, _b, _c, _d;
|
|
1146
1146
|
try {
|
|
1147
1147
|
const session = await api.getSessionFromCtx(ctx);
|
|
1148
1148
|
const user = session == null ? void 0 : session.user;
|
|
1149
1149
|
if (!user) return;
|
|
1150
1150
|
const ip = getClientIp(ctx.headers);
|
|
1151
|
-
await
|
|
1151
|
+
await log({
|
|
1152
1152
|
userId: user.id,
|
|
1153
1153
|
action: action === "added" ? "passkey_added" : "passkey_removed",
|
|
1154
1154
|
description: `Passkey ${action}`,
|
|
@@ -1175,12 +1175,12 @@ async function notifyPasskeyChange(ctx, action) {
|
|
|
1175
1175
|
console.error("Failed to send passkey-change notification", error);
|
|
1176
1176
|
}
|
|
1177
1177
|
}
|
|
1178
|
-
async function packageSessionCreated(...[session, context]) {
|
|
1178
|
+
async function packageSessionCreated(log, ...[session, context]) {
|
|
1179
1179
|
var _a, _b, _c, _d;
|
|
1180
1180
|
const impersonatedBy = session.impersonatedBy;
|
|
1181
1181
|
if (impersonatedBy) {
|
|
1182
1182
|
const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, session.userId)).limit(1);
|
|
1183
|
-
await
|
|
1183
|
+
await log({
|
|
1184
1184
|
userId: impersonatedBy,
|
|
1185
1185
|
action: "impersonation_started",
|
|
1186
1186
|
description: `Admin started impersonating ${(_b = (_a = target[0]) == null ? void 0 : _a.email) != null ? _b : session.userId}`,
|
|
@@ -1202,7 +1202,7 @@ async function packageSessionCreated(...[session, context]) {
|
|
|
1202
1202
|
const geo = lookupGeoLocation(ipAddress);
|
|
1203
1203
|
const [{ count }] = await db.select({ count: drizzleOrm.sql`count(*)` }).from(sessions).where(drizzleOrm.eq(sessions.userId, session.userId));
|
|
1204
1204
|
const isFirstSession = Number(count) <= 1;
|
|
1205
|
-
await
|
|
1205
|
+
await log({
|
|
1206
1206
|
userId: session.userId,
|
|
1207
1207
|
action: "login",
|
|
1208
1208
|
description: isFirstSession ? "New account registered and signed in" : "User logged in",
|
|
@@ -1220,7 +1220,7 @@ async function packageSessionCreated(...[session, context]) {
|
|
|
1220
1220
|
}
|
|
1221
1221
|
}
|
|
1222
1222
|
function createAuth(overrides = {}) {
|
|
1223
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1223
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1224
1224
|
const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
|
|
1225
1225
|
google: {
|
|
1226
1226
|
clientId: process.env.AUTH_GOOGLE_ID || process.env.GOOGLE_CLIENT_ID || "",
|
|
@@ -1235,16 +1235,17 @@ function createAuth(overrides = {}) {
|
|
|
1235
1235
|
);
|
|
1236
1236
|
}
|
|
1237
1237
|
const baseURL = process.env.NEXTAUTH_URL || process.env.BETTER_AUTH_URL || "http://localhost:3000";
|
|
1238
|
+
const log = (_a = overrides.logActivity) != null ? _a : logActivity;
|
|
1238
1239
|
const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
|
|
1239
1240
|
issuer: config.APP_NAME,
|
|
1240
|
-
passwordless: (
|
|
1241
|
-
challengeAfterOAuth: (
|
|
1241
|
+
passwordless: (_b = overrides.twoFactor) == null ? void 0 : _b.passwordless,
|
|
1242
|
+
challengeAfterOAuth: (_c = overrides.twoFactor) == null ? void 0 : _c.challengeAfterOAuth
|
|
1242
1243
|
});
|
|
1243
1244
|
const appHooks = {
|
|
1244
1245
|
id: "app-hooks",
|
|
1245
1246
|
hooks: {
|
|
1246
|
-
before: ((
|
|
1247
|
-
after: ((
|
|
1247
|
+
before: ((_d = overrides.hooks) == null ? void 0 : _d.before) ? [{ matcher: () => true, handler: overrides.hooks.before }] : [],
|
|
1248
|
+
after: ((_e = overrides.hooks) == null ? void 0 : _e.after) ? [{ matcher: () => true, handler: overrides.hooks.after }] : []
|
|
1248
1249
|
}
|
|
1249
1250
|
};
|
|
1250
1251
|
return betterAuth.betterAuth({
|
|
@@ -1326,7 +1327,7 @@ function createAuth(overrides = {}) {
|
|
|
1326
1327
|
// no password, so better-auth instead requires a session younger than
|
|
1327
1328
|
// `freshAge` (default 1 day). Every user-owned table cascades on delete.
|
|
1328
1329
|
// Impersonation and last-admin guards live in hooks.before below.
|
|
1329
|
-
deleteUser: { enabled: (
|
|
1330
|
+
deleteUser: { enabled: (_f = overrides.deleteUser) != null ? _f : true }
|
|
1330
1331
|
},
|
|
1331
1332
|
// Advanced options
|
|
1332
1333
|
advanced: __spreadProps(__spreadValues({}, overrides.advanced), {
|
|
@@ -1348,7 +1349,7 @@ function createAuth(overrides = {}) {
|
|
|
1348
1349
|
create: {
|
|
1349
1350
|
async after(session, context) {
|
|
1350
1351
|
var _a2, _b2, _c2, _d2;
|
|
1351
|
-
await packageSessionCreated(session, context);
|
|
1352
|
+
await packageSessionCreated(log, session, context);
|
|
1352
1353
|
await ((_d2 = (_c2 = (_b2 = (_a2 = overrides.databaseHooks) == null ? void 0 : _a2.session) == null ? void 0 : _b2.create) == null ? void 0 : _c2.after) == null ? void 0 : _d2.call(_c2, session, context));
|
|
1353
1354
|
}
|
|
1354
1355
|
}
|
|
@@ -1418,7 +1419,7 @@ function createAuth(overrides = {}) {
|
|
|
1418
1419
|
const current = await api.getSessionFromCtx(ctx, { disableCookieCache: true });
|
|
1419
1420
|
if (current == null ? void 0 : current.session.impersonatedBy) {
|
|
1420
1421
|
const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, current.session.userId)).limit(1);
|
|
1421
|
-
await
|
|
1422
|
+
await log({
|
|
1422
1423
|
userId: current.session.impersonatedBy,
|
|
1423
1424
|
action: "impersonation_stopped",
|
|
1424
1425
|
description: `Admin stopped impersonating ${(_d2 = (_c2 = target[0]) == null ? void 0 : _c2.email) != null ? _d2 : current.session.userId}`,
|
|
@@ -1432,7 +1433,8 @@ function createAuth(overrides = {}) {
|
|
|
1432
1433
|
if (ctx.context.returned instanceof api.APIError) return;
|
|
1433
1434
|
await notifyPasskeyChange(
|
|
1434
1435
|
ctx,
|
|
1435
|
-
ctx.path === "/passkey/verify-registration" ? "added" : "removed"
|
|
1436
|
+
ctx.path === "/passkey/verify-registration" ? "added" : "removed",
|
|
1437
|
+
log
|
|
1436
1438
|
);
|
|
1437
1439
|
return;
|
|
1438
1440
|
}
|
|
@@ -1455,7 +1457,7 @@ function createAuth(overrides = {}) {
|
|
|
1455
1457
|
}
|
|
1456
1458
|
if (failed) {
|
|
1457
1459
|
await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
|
|
1458
|
-
await logFailedLogin(ctx);
|
|
1460
|
+
await logFailedLogin(ctx, log);
|
|
1459
1461
|
} else {
|
|
1460
1462
|
await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
|
|
1461
1463
|
}
|
|
@@ -1510,7 +1512,7 @@ function createAuth(overrides = {}) {
|
|
|
1510
1512
|
// array and better-auth 1.7 then drops plugin fields (e.g. session.impersonatedBy).
|
|
1511
1513
|
...config.AUTH_ENABLE_ONE_TAP && Boolean(socialProviders.google) ? [plugins.oneTap()] : [],
|
|
1512
1514
|
appHooks,
|
|
1513
|
-
...(
|
|
1515
|
+
...(_g = overrides.plugins) != null ? _g : []
|
|
1514
1516
|
]
|
|
1515
1517
|
});
|
|
1516
1518
|
}
|