@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
@@ -263,6 +263,8 @@ var users = pgCore.pgTable("user", {
263
263
  banned: pgCore.boolean("banned").default(false).notNull(),
264
264
  bannedAt: pgCore.timestamp("bannedAt"),
265
265
  bannedReason: pgCore.text("bannedReason"),
266
+ bannedBy: pgCore.text("bannedBy"),
267
+ // email of the admin who issued the ban
266
268
  // Required by better-auth's admin plugin schema (auto-expiring bans). We
267
269
  // never set this ourselves, so it stays null and bans behave as permanent,
268
270
  // same as before the plugin was added.
@@ -1123,7 +1125,7 @@ async function getResend() {
1123
1125
  config.RESEND_BROADCAST_API_KEY || config.RESEND_API_KEY;
1124
1126
 
1125
1127
  // server/auth.ts
1126
- async function logFailedLogin(ctx) {
1128
+ async function logFailedLogin(ctx, log) {
1127
1129
  var _a, _b, _c;
1128
1130
  try {
1129
1131
  const raw = (_a = ctx.body) == null ? void 0 : _a.email;
@@ -1131,7 +1133,7 @@ async function logFailedLogin(ctx) {
1131
1133
  if (!email) return;
1132
1134
  const [user] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.email, email)).limit(1);
1133
1135
  if (!user) return;
1134
- await logActivity({
1136
+ await log({
1135
1137
  userId: user.id,
1136
1138
  action: "login_failed",
1137
1139
  description: "Failed login attempt",
@@ -1142,14 +1144,14 @@ async function logFailedLogin(ctx) {
1142
1144
  console.error("Failed to log login_failed activity", error);
1143
1145
  }
1144
1146
  }
1145
- async function notifyPasskeyChange(ctx, action) {
1147
+ async function notifyPasskeyChange(ctx, action, log) {
1146
1148
  var _a, _b, _c, _d;
1147
1149
  try {
1148
1150
  const session = await api.getSessionFromCtx(ctx);
1149
1151
  const user = session == null ? void 0 : session.user;
1150
1152
  if (!user) return;
1151
1153
  const ip = getClientIp(ctx.headers);
1152
- await logActivity({
1154
+ await log({
1153
1155
  userId: user.id,
1154
1156
  action: action === "added" ? "passkey_added" : "passkey_removed",
1155
1157
  description: `Passkey ${action}`,
@@ -1176,12 +1178,12 @@ async function notifyPasskeyChange(ctx, action) {
1176
1178
  console.error("Failed to send passkey-change notification", error);
1177
1179
  }
1178
1180
  }
1179
- async function packageSessionCreated(...[session, context]) {
1181
+ async function packageSessionCreated(log, ...[session, context]) {
1180
1182
  var _a, _b, _c, _d;
1181
1183
  const impersonatedBy = session.impersonatedBy;
1182
1184
  if (impersonatedBy) {
1183
1185
  const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, session.userId)).limit(1);
1184
- await logActivity({
1186
+ await log({
1185
1187
  userId: impersonatedBy,
1186
1188
  action: "impersonation_started",
1187
1189
  description: `Admin started impersonating ${(_b = (_a = target[0]) == null ? void 0 : _a.email) != null ? _b : session.userId}`,
@@ -1203,7 +1205,7 @@ async function packageSessionCreated(...[session, context]) {
1203
1205
  const geo = lookupGeoLocation(ipAddress);
1204
1206
  const [{ count }] = await db.select({ count: drizzleOrm.sql`count(*)` }).from(sessions).where(drizzleOrm.eq(sessions.userId, session.userId));
1205
1207
  const isFirstSession = Number(count) <= 1;
1206
- await logActivity({
1208
+ await log({
1207
1209
  userId: session.userId,
1208
1210
  action: "login",
1209
1211
  description: isFirstSession ? "New account registered and signed in" : "User logged in",
@@ -1221,7 +1223,7 @@ async function packageSessionCreated(...[session, context]) {
1221
1223
  }
1222
1224
  }
1223
1225
  function createAuth(overrides = {}) {
1224
- var _a, _b, _c, _d, _e, _f;
1226
+ var _a, _b, _c, _d, _e, _f, _g;
1225
1227
  const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
1226
1228
  google: {
1227
1229
  clientId: process.env.AUTH_GOOGLE_ID || process.env.GOOGLE_CLIENT_ID || "",
@@ -1236,16 +1238,17 @@ function createAuth(overrides = {}) {
1236
1238
  );
1237
1239
  }
1238
1240
  const baseURL = process.env.NEXTAUTH_URL || process.env.BETTER_AUTH_URL || "http://localhost:3000";
1241
+ const log = (_a = overrides.logActivity) != null ? _a : logActivity;
1239
1242
  const [twoFactorPlugin, twoFactorExtras] = twoFactorPlugins(baseURL, {
1240
1243
  issuer: config.APP_NAME,
1241
- passwordless: (_a = overrides.twoFactor) == null ? void 0 : _a.passwordless,
1242
- challengeAfterOAuth: (_b = overrides.twoFactor) == null ? void 0 : _b.challengeAfterOAuth
1244
+ passwordless: (_b = overrides.twoFactor) == null ? void 0 : _b.passwordless,
1245
+ challengeAfterOAuth: (_c = overrides.twoFactor) == null ? void 0 : _c.challengeAfterOAuth
1243
1246
  });
1244
1247
  const appHooks = {
1245
1248
  id: "app-hooks",
1246
1249
  hooks: {
1247
- before: ((_c = overrides.hooks) == null ? void 0 : _c.before) ? [{ matcher: () => true, handler: overrides.hooks.before }] : [],
1248
- after: ((_d = overrides.hooks) == null ? void 0 : _d.after) ? [{ matcher: () => true, handler: overrides.hooks.after }] : []
1250
+ before: ((_d = overrides.hooks) == null ? void 0 : _d.before) ? [{ matcher: () => true, handler: overrides.hooks.before }] : [],
1251
+ after: ((_e = overrides.hooks) == null ? void 0 : _e.after) ? [{ matcher: () => true, handler: overrides.hooks.after }] : []
1249
1252
  }
1250
1253
  };
1251
1254
  return betterAuth.betterAuth({
@@ -1327,7 +1330,7 @@ function createAuth(overrides = {}) {
1327
1330
  // no password, so better-auth instead requires a session younger than
1328
1331
  // `freshAge` (default 1 day). Every user-owned table cascades on delete.
1329
1332
  // Impersonation and last-admin guards live in hooks.before below.
1330
- deleteUser: { enabled: (_e = overrides.deleteUser) != null ? _e : true }
1333
+ deleteUser: { enabled: (_f = overrides.deleteUser) != null ? _f : true }
1331
1334
  },
1332
1335
  // Advanced options
1333
1336
  advanced: __spreadProps(__spreadValues({}, overrides.advanced), {
@@ -1349,7 +1352,7 @@ function createAuth(overrides = {}) {
1349
1352
  create: {
1350
1353
  async after(session, context) {
1351
1354
  var _a2, _b2, _c2, _d2;
1352
- await packageSessionCreated(session, context);
1355
+ await packageSessionCreated(log, session, context);
1353
1356
  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));
1354
1357
  }
1355
1358
  }
@@ -1419,7 +1422,7 @@ function createAuth(overrides = {}) {
1419
1422
  const current = await api.getSessionFromCtx(ctx, { disableCookieCache: true });
1420
1423
  if (current == null ? void 0 : current.session.impersonatedBy) {
1421
1424
  const target = await db.select({ email: users.email }).from(users).where(drizzleOrm.eq(users.id, current.session.userId)).limit(1);
1422
- await logActivity({
1425
+ await log({
1423
1426
  userId: current.session.impersonatedBy,
1424
1427
  action: "impersonation_stopped",
1425
1428
  description: `Admin stopped impersonating ${(_d2 = (_c2 = target[0]) == null ? void 0 : _c2.email) != null ? _d2 : current.session.userId}`,
@@ -1433,7 +1436,8 @@ function createAuth(overrides = {}) {
1433
1436
  if (ctx.context.returned instanceof api.APIError) return;
1434
1437
  await notifyPasskeyChange(
1435
1438
  ctx,
1436
- ctx.path === "/passkey/verify-registration" ? "added" : "removed"
1439
+ ctx.path === "/passkey/verify-registration" ? "added" : "removed",
1440
+ log
1437
1441
  );
1438
1442
  return;
1439
1443
  }
@@ -1456,7 +1460,7 @@ function createAuth(overrides = {}) {
1456
1460
  }
1457
1461
  if (failed) {
1458
1462
  await Promise.all(keys.map((key) => recordDeviceAttempt(key, __spreadProps(__spreadValues({}, meta), { kind: "signin" }))));
1459
- await logFailedLogin(ctx);
1463
+ await logFailedLogin(ctx, log);
1460
1464
  } else {
1461
1465
  await Promise.all(keys.map((key) => clearDeviceThrottle(key)));
1462
1466
  }
@@ -1511,7 +1515,7 @@ function createAuth(overrides = {}) {
1511
1515
  // array and better-auth 1.7 then drops plugin fields (e.g. session.impersonatedBy).
1512
1516
  ...config.AUTH_ENABLE_ONE_TAP && Boolean(socialProviders.google) ? [plugins.oneTap()] : [],
1513
1517
  appHooks,
1514
- ...(_f = overrides.plugins) != null ? _f : []
1518
+ ...(_g = overrides.plugins) != null ? _g : []
1515
1519
  ]
1516
1520
  });
1517
1521
  }