@xk2800/nextjs-template 0.7.2-beta.1 → 0.7.2-beta.2

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.
@@ -1239,6 +1239,14 @@ async function packageSessionCreated(log, ...[session, context]) {
1239
1239
  console.error("Failed to log login activity", error);
1240
1240
  }
1241
1241
  }
1242
+ async function promoteFirstAdmin(user) {
1243
+ var _a;
1244
+ const adminEmail = (_a = process.env.ADMIN_EMAIL) == null ? void 0 : _a.trim().toLowerCase();
1245
+ if (!adminEmail || !user.emailVerified || user.email.toLowerCase() !== adminEmail) return;
1246
+ const [existing] = await db.select({ id: users.id }).from(users).where(drizzleOrm.eq(users.role, "admin")).limit(1);
1247
+ if (existing) return;
1248
+ await db.update(users).set({ role: "admin" }).where(drizzleOrm.eq(users.id, user.id));
1249
+ }
1242
1250
  function createAuth(overrides = {}) {
1243
1251
  var _a, _b, _c, _d, _e, _f, _g;
1244
1252
  const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
@@ -1318,6 +1326,9 @@ function createAuth(overrides = {}) {
1318
1326
  // callback that flips users.emailVerified on click.
1319
1327
  emailVerification: {
1320
1328
  autoSignInAfterVerification: true,
1329
+ async afterEmailVerification(user) {
1330
+ await promoteFirstAdmin(user);
1331
+ },
1321
1332
  async sendVerificationEmail({ user, url }) {
1322
1333
  const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_email_template_verify_email(), email_template_verify_email_exports));
1323
1334
  await (await getResend()).emails.send({
@@ -1361,6 +1372,7 @@ function createAuth(overrides = {}) {
1361
1372
  create: {
1362
1373
  async after(user, context) {
1363
1374
  var _a2, _b2, _c2, _d2;
1375
+ await promoteFirstAdmin(user);
1364
1376
  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));
1365
1377
  }
1366
1378
  }