@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.
@@ -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-K2GCSLRJ.mjs';
3
3
  import '../chunk-O5EQYHNC.mjs';
4
4
  import '../chunk-6OAHCEDJ.mjs';
5
5
  import { getSystemSettings } from '../chunk-2BJ3B4FR.mjs';
@@ -1249,6 +1249,14 @@ 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
+ }
1252
1260
  function createAuth(overrides = {}) {
1253
1261
  var _a, _b, _c, _d, _e, _f, _g;
1254
1262
  const socialProviders = __spreadValues(__spreadValues({}, config.AUTH_ENABLE_GOOGLE ? {
@@ -1328,6 +1336,9 @@ function createAuth(overrides = {}) {
1328
1336
  // callback that flips users.emailVerified on click.
1329
1337
  emailVerification: {
1330
1338
  autoSignInAfterVerification: true,
1339
+ async afterEmailVerification(user) {
1340
+ await promoteFirstAdmin(user);
1341
+ },
1331
1342
  async sendVerificationEmail({ user, url }) {
1332
1343
  const { EmailTemplateVerifyEmail: EmailTemplateVerifyEmail2 } = await Promise.resolve().then(() => (init_email_template_verify_email(), email_template_verify_email_exports));
1333
1344
  await (await getResend()).emails.send({
@@ -1371,6 +1382,7 @@ function createAuth(overrides = {}) {
1371
1382
  create: {
1372
1383
  async after(user, context) {
1373
1384
  var _a2, _b2, _c2, _d2;
1385
+ await promoteFirstAdmin(user);
1374
1386
  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
1387
  }
1376
1388
  }