@xk2800/nextjs-template 0.7.1-beta.16 → 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.
Files changed (75) hide show
  1. package/components/dashboard/admin/adminUsersTable.tsx +154 -34
  2. package/components/email/email-template-banned.tsx +53 -0
  3. package/dist/activity/logger.d.mts +3 -1
  4. package/dist/activity/logger.d.ts +3 -1
  5. package/dist/activity/logger.js +2 -0
  6. package/dist/activity/logger.js.map +1 -1
  7. package/dist/activity/logger.mjs +3 -3
  8. package/dist/activity/queries.d.mts +1 -1
  9. package/dist/activity/queries.d.ts +1 -1
  10. package/dist/activity/queries.js +2 -0
  11. package/dist/activity/queries.js.map +1 -1
  12. package/dist/activity/queries.mjs +2 -2
  13. package/dist/admin/queries.js +2 -0
  14. package/dist/admin/queries.js.map +1 -1
  15. package/dist/admin/queries.mjs +2 -2
  16. package/dist/api/feedback.js +22 -18
  17. package/dist/api/feedback.js.map +1 -1
  18. package/dist/api/feedback.mjs +6 -6
  19. package/dist/api/marketing.js +22 -18
  20. package/dist/api/marketing.js.map +1 -1
  21. package/dist/api/marketing.mjs +7 -7
  22. package/dist/auth/helpers.js +22 -18
  23. package/dist/auth/helpers.js.map +1 -1
  24. package/dist/auth/helpers.mjs +6 -6
  25. package/dist/auth/index.d.mts +9 -2
  26. package/dist/auth/index.d.ts +9 -2
  27. package/dist/auth/index.js +22 -18
  28. package/dist/auth/index.js.map +1 -1
  29. package/dist/auth/index.mjs +5 -5
  30. package/dist/{chunk-P2G23JMY.mjs → chunk-2BML32KG.mjs} +4 -4
  31. package/dist/{chunk-P2G23JMY.mjs.map → chunk-2BML32KG.mjs.map} +1 -1
  32. package/dist/{chunk-A2K3FVDH.mjs → chunk-3BVXDGVH.mjs} +5 -5
  33. package/dist/{chunk-A2K3FVDH.mjs.map → chunk-3BVXDGVH.mjs.map} +1 -1
  34. package/dist/{chunk-WJMWCE2I.mjs → chunk-BZ6BJNYZ.mjs} +26 -24
  35. package/dist/chunk-BZ6BJNYZ.mjs.map +1 -0
  36. package/dist/{chunk-7F2POZM6.mjs → chunk-KLQOKDIL.mjs} +4 -4
  37. package/dist/chunk-KLQOKDIL.mjs.map +1 -0
  38. package/dist/{chunk-6MDQRT6U.mjs → chunk-KX2M6OEG.mjs} +4 -4
  39. package/dist/{chunk-6MDQRT6U.mjs.map → chunk-KX2M6OEG.mjs.map} +1 -1
  40. package/dist/{chunk-TR5XFBTD.mjs → chunk-U23QCUKV.mjs} +4 -2
  41. package/dist/chunk-U23QCUKV.mjs.map +1 -0
  42. package/dist/{chunk-ZJMFE5B2.mjs → chunk-YNA4OYKO.mjs} +3 -3
  43. package/dist/{chunk-ZJMFE5B2.mjs.map → chunk-YNA4OYKO.mjs.map} +1 -1
  44. package/dist/db/index.d.mts +1 -1
  45. package/dist/db/index.d.ts +1 -1
  46. package/dist/db/index.js +2 -0
  47. package/dist/db/index.js.map +1 -1
  48. package/dist/db/index.mjs +2 -2
  49. package/dist/db/schema.d.mts +1 -1
  50. package/dist/db/schema.d.ts +1 -1
  51. package/dist/db/schema.js +2 -0
  52. package/dist/db/schema.js.map +1 -1
  53. package/dist/db/schema.mjs +1 -1
  54. package/dist/errors.js +2 -0
  55. package/dist/errors.js.map +1 -1
  56. package/dist/errors.mjs +3 -3
  57. package/dist/{schema-CN_Y6EXv.d.mts → schema-B_3Oe9DD.d.mts} +18 -1
  58. package/dist/{schema-CN_Y6EXv.d.ts → schema-B_3Oe9DD.d.ts} +18 -1
  59. package/dist/sessions/queries.js +2 -0
  60. package/dist/sessions/queries.js.map +1 -1
  61. package/dist/sessions/queries.mjs +2 -2
  62. package/dist/settings/queries.d.mts +1 -1
  63. package/dist/settings/queries.d.ts +1 -1
  64. package/dist/settings/queries.js +2 -0
  65. package/dist/settings/queries.js.map +1 -1
  66. package/dist/settings/queries.mjs +3 -3
  67. package/dist/users/queries.d.mts +3 -0
  68. package/dist/users/queries.d.ts +3 -0
  69. package/dist/users/queries.js +2 -0
  70. package/dist/users/queries.js.map +1 -1
  71. package/dist/users/queries.mjs +2 -2
  72. package/package.json +1 -1
  73. package/dist/chunk-7F2POZM6.mjs.map +0 -1
  74. package/dist/chunk-TR5XFBTD.mjs.map +0 -1
  75. package/dist/chunk-WJMWCE2I.mjs.map +0 -1
@@ -1,11 +1,11 @@
1
- import { lookupErrorDetail, unexpectedErrorMessage } from '../chunk-6MDQRT6U.mjs';
2
- import { auth } from '../chunk-WJMWCE2I.mjs';
3
- import '../chunk-7F2POZM6.mjs';
1
+ import { lookupErrorDetail, unexpectedErrorMessage } from '../chunk-KX2M6OEG.mjs';
2
+ import { auth } from '../chunk-BZ6BJNYZ.mjs';
3
+ import '../chunk-KLQOKDIL.mjs';
4
4
  import '../chunk-6OAHCEDJ.mjs';
5
- import { getSystemSettings } from '../chunk-P2G23JMY.mjs';
5
+ import { getSystemSettings } from '../chunk-2BML32KG.mjs';
6
6
  import { getResend, EMAIL_FROM } from '../chunk-OVKVD2HH.mjs';
7
- import '../chunk-ZJMFE5B2.mjs';
8
- import '../chunk-TR5XFBTD.mjs';
7
+ import '../chunk-YNA4OYKO.mjs';
8
+ import '../chunk-U23QCUKV.mjs';
9
9
  import { config } from '../chunk-TKWNEKK6.mjs';
10
10
  import '../chunk-3465SI5N.mjs';
11
11
  import 'server-only';
@@ -265,6 +265,8 @@ var users = pgCore.pgTable("user", {
265
265
  banned: pgCore.boolean("banned").default(false).notNull(),
266
266
  bannedAt: pgCore.timestamp("bannedAt"),
267
267
  bannedReason: pgCore.text("bannedReason"),
268
+ bannedBy: pgCore.text("bannedBy"),
269
+ // email of the admin who issued the ban
268
270
  // Required by better-auth's admin plugin schema (auto-expiring bans). We
269
271
  // never set this ourselves, so it stays null and bans behave as permanent,
270
272
  // same as before the plugin was added.
@@ -1133,7 +1135,7 @@ async function getBroadcastResend() {
1133
1135
  }
1134
1136
 
1135
1137
  // server/auth.ts
1136
- async function logFailedLogin(ctx) {
1138
+ async function logFailedLogin(ctx, log) {
1137
1139
  var _a, _b, _c;
1138
1140
  try {
1139
1141
  const raw = (_a = ctx.body) == null ? void 0 : _a.email;
@@ -1141,7 +1143,7 @@ async function logFailedLogin(ctx) {
1141
1143
  if (!email) return;
1142
1144
  const [user] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.email, email)).limit(1);
1143
1145
  if (!user) return;
1144
- await logActivity({
1146
+ await log({
1145
1147
  userId: user.id,
1146
1148
  action: "login_failed",
1147
1149
  description: "Failed login attempt",
@@ -1152,14 +1154,14 @@ async function logFailedLogin(ctx) {
1152
1154
  console.error("Failed to log login_failed activity", error);
1153
1155
  }
1154
1156
  }
1155
- async function notifyPasskeyChange(ctx, action) {
1157
+ async function notifyPasskeyChange(ctx, action, log) {
1156
1158
  var _a, _b, _c, _d;
1157
1159
  try {
1158
1160
  const session = await api.getSessionFromCtx(ctx);
1159
1161
  const user = session == null ? void 0 : session.user;
1160
1162
  if (!user) return;
1161
1163
  const ip = getClientIp(ctx.headers);
1162
- await logActivity({
1164
+ await log({
1163
1165
  userId: user.id,
1164
1166
  action: action === "added" ? "passkey_added" : "passkey_removed",
1165
1167
  description: `Passkey ${action}`,
@@ -1186,12 +1188,12 @@ async function notifyPasskeyChange(ctx, action) {
1186
1188
  console.error("Failed to send passkey-change notification", error);
1187
1189
  }
1188
1190
  }
1189
- async function packageSessionCreated(...[session, context]) {
1191
+ async function packageSessionCreated(log, ...[session, context]) {
1190
1192
  var _a, _b, _c, _d;
1191
1193
  const impersonatedBy = session.impersonatedBy;
1192
1194
  if (impersonatedBy) {
1193
1195
  const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, session.userId)).limit(1);
1194
- await logActivity({
1196
+ await log({
1195
1197
  userId: impersonatedBy,
1196
1198
  action: "impersonation_started",
1197
1199
  description: `Admin started impersonating ${(_b = (_a = target[0]) == null ? void 0 : _a.email) != null ? _b : session.userId}`,
@@ -1213,7 +1215,7 @@ async function packageSessionCreated(...[session, context]) {
1213
1215
  const geo = lookupGeoLocation(ipAddress);
1214
1216
  const [{ count }] = await db.select({ count: drizzleOrm.sql`count(*)` }).from(sessions).where(drizzleOrm.eq(sessions.userId, session.userId));
1215
1217
  const isFirstSession = Number(count) <= 1;
1216
- await logActivity({
1218
+ await log({
1217
1219
  userId: session.userId,
1218
1220
  action: "login",
1219
1221
  description: isFirstSession ? "New account registered and signed in" : "User logged in",
@@ -1231,7 +1233,7 @@ async function packageSessionCreated(...[session, context]) {
1231
1233
  }
1232
1234
  }
1233
1235
  function createAuth(overrides = {}) {
1234
- var _a, _b, _c, _d, _e, _f;
1236
+ var _a, _b, _c, _d, _e, _f, _g;
1235
1237
  const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
1236
1238
  google: {
1237
1239
  clientId: process.env.AUTH_GOOGLE_ID || process.env.GOOGLE_CLIENT_ID || "",
@@ -1246,16 +1248,17 @@ function createAuth(overrides = {}) {
1246
1248
  );
1247
1249
  }
1248
1250
  const baseURL = process.env.NEXTAUTH_URL || process.env.BETTER_AUTH_URL || "http://localhost:3000";
1251
+ const log = (_a = overrides.logActivity) != null ? _a : logActivity;
1249
1252
  const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
1250
1253
  issuer: config.APP_NAME,
1251
- passwordless: (_a = overrides.twoFactor) == null ? void 0 : _a.passwordless,
1252
- challengeAfterOAuth: (_b = overrides.twoFactor) == null ? void 0 : _b.challengeAfterOAuth
1254
+ passwordless: (_b = overrides.twoFactor) == null ? void 0 : _b.passwordless,
1255
+ challengeAfterOAuth: (_c = overrides.twoFactor) == null ? void 0 : _c.challengeAfterOAuth
1253
1256
  });
1254
1257
  const appHooks = {
1255
1258
  id: "app-hooks",
1256
1259
  hooks: {
1257
- before: ((_c = overrides.hooks) == null ? void 0 : _c.before) ? [{ matcher: () => true, handler: overrides.hooks.before }] : [],
1258
- after: ((_d = overrides.hooks) == null ? void 0 : _d.after) ? [{ matcher: () => true, handler: overrides.hooks.after }] : []
1260
+ before: ((_d = overrides.hooks) == null ? void 0 : _d.before) ? [{ matcher: () => true, handler: overrides.hooks.before }] : [],
1261
+ after: ((_e = overrides.hooks) == null ? void 0 : _e.after) ? [{ matcher: () => true, handler: overrides.hooks.after }] : []
1259
1262
  }
1260
1263
  };
1261
1264
  return betterAuth.betterAuth({
@@ -1337,7 +1340,7 @@ function createAuth(overrides = {}) {
1337
1340
  // no password, so better-auth instead requires a session younger than
1338
1341
  // `freshAge` (default 1 day). Every user-owned table cascades on delete.
1339
1342
  // Impersonation and last-admin guards live in hooks.before below.
1340
- deleteUser: { enabled: (_e = overrides.deleteUser) != null ? _e : true }
1343
+ deleteUser: { enabled: (_f = overrides.deleteUser) != null ? _f : true }
1341
1344
  },
1342
1345
  // Advanced options
1343
1346
  advanced: __spreadProps(__spreadValues({}, overrides.advanced), {
@@ -1359,7 +1362,7 @@ function createAuth(overrides = {}) {
1359
1362
  create: {
1360
1363
  async after(session, context) {
1361
1364
  var _a2, _b2, _c2, _d2;
1362
- await packageSessionCreated(session, context);
1365
+ await packageSessionCreated(log, session, context);
1363
1366
  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));
1364
1367
  }
1365
1368
  }
@@ -1429,7 +1432,7 @@ function createAuth(overrides = {}) {
1429
1432
  const current = await api.getSessionFromCtx(ctx, { disableCookieCache: true });
1430
1433
  if (current == null ? void 0 : current.session.impersonatedBy) {
1431
1434
  const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, current.session.userId)).limit(1);
1432
- await logActivity({
1435
+ await log({
1433
1436
  userId: current.session.impersonatedBy,
1434
1437
  action: "impersonation_stopped",
1435
1438
  description: `Admin stopped impersonating ${(_d2 = (_c2 = target[0]) == null ? void 0 : _c2.email) != null ? _d2 : current.session.userId}`,
@@ -1443,7 +1446,8 @@ function createAuth(overrides = {}) {
1443
1446
  if (ctx.context.returned instanceof api.APIError) return;
1444
1447
  await notifyPasskeyChange(
1445
1448
  ctx,
1446
- ctx.path === "/passkey/verify-registration" ? "added" : "removed"
1449
+ ctx.path === "/passkey/verify-registration" ? "added" : "removed",
1450
+ log
1447
1451
  );
1448
1452
  return;
1449
1453
  }
@@ -1466,7 +1470,7 @@ function createAuth(overrides = {}) {
1466
1470
  }
1467
1471
  if (failed) {
1468
1472
  await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
1469
- await logFailedLogin(ctx);
1473
+ await logFailedLogin(ctx, log);
1470
1474
  } else {
1471
1475
  await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
1472
1476
  }
@@ -1521,7 +1525,7 @@ function createAuth(overrides = {}) {
1521
1525
  // array and better-auth 1.7 then drops plugin fields (e.g. session.impersonatedBy).
1522
1526
  ...config.AUTH_ENABLE_ONE_TAP && Boolean(socialProviders.google) ? [plugins.oneTap()] : [],
1523
1527
  appHooks,
1524
- ...(_f = overrides.plugins) != null ? _f : []
1528
+ ...(_g = overrides.plugins) != null ? _g : []
1525
1529
  ]
1526
1530
  });
1527
1531
  }