@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-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.
@@ -1,5 +1,5 @@
1
1
  import { lookupErrorDetail, unexpectedErrorMessage } from '../chunk-653GF7OT.mjs';
2
- import { auth } from '../chunk-EIS4SCQW.mjs';
2
+ import { auth } from '../chunk-ONJDPUVO.mjs';
3
3
  import '../chunk-O5EQYHNC.mjs';
4
4
  import '../chunk-6OAHCEDJ.mjs';
5
5
  import { getSystemSettings } from '../chunk-2BJ3B4FR.mjs';
@@ -1249,6 +1249,15 @@ async function packageSessionCreated(log, ...[session, context]) {
1249
1249
  console.error("Failed to log login activity", error);
1250
1250
  }
1251
1251
  }
1252
+ async function promoteFirstAdmin(user) {
1253
+ var _a;
1254
+ const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
1255
+ if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
1256
+ const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
1257
+ if (existing) return;
1258
+ await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
1259
+ user.role = "admin";
1260
+ }
1252
1261
  function createAuth(overrides = {}) {
1253
1262
  var _a, _b, _c, _d, _e, _f, _g;
1254
1263
  const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
@@ -1328,6 +1337,9 @@ function createAuth(overrides = {}) {
1328
1337
  // callback that flips users.emailVerified on click.
1329
1338
  emailVerification: {
1330
1339
  autoSignInAfterVerification: true,
1340
+ async afterEmailVerification(user) {
1341
+ await promoteFirstAdmin(user);
1342
+ },
1331
1343
  async sendVerificationEmail({ user, url }) {
1332
1344
  const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_email_template_verify_email(), email_template_verify_email_exports));
1333
1345
  await (await getResend()).emails.send({
@@ -1371,6 +1383,7 @@ function createAuth(overrides = {}) {
1371
1383
  create: {
1372
1384
  async after(user, context) {
1373
1385
  var _a2, _b2, _c2, _d2;
1386
+ await promoteFirstAdmin(user);
1374
1387
  await ((_d2 = (_c2 = (_b2 = (_a2 = overrides.databaseHooks) == null ? void 0 : _a2.user) == null ? void 0 : _b2.create) == null ? void 0 : _c2.after) == null ? void 0 : _d2.call(_c2, user, context));
1375
1388
  }
1376
1389
  }