@alinsafawi/aegis-auth 0.1.9 → 0.2.0

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 (2) hide show
  1. package/dist/index.js +74 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23607,11 +23607,12 @@ export default function RootPage() {
23607
23607
  }
23608
23608
  function generateMiddleware(cookiePrefix, language) {
23609
23609
  return `import { createAuthMiddleware } from '@alinsafawi/aegis-auth-next'
23610
- import config from './auth.config'
23610
+ import authConfig from './auth.config'
23611
23611
 
23612
- export default createAuthMiddleware(config)
23612
+ export default createAuthMiddleware(authConfig)
23613
23613
 
23614
23614
  export const config = {
23615
+ runtime: 'nodejs',
23615
23616
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
23616
23617
  }
23617
23618
  `;
@@ -23726,7 +23727,11 @@ export default function LoginPage() {
23726
23727
  function generateNextConfig() {
23727
23728
  return `import type { NextConfig } from 'next'
23728
23729
 
23729
- const nextConfig: NextConfig = {}
23730
+ const nextConfig: NextConfig = {
23731
+ experimental: {
23732
+ nodeMiddleware: true,
23733
+ },
23734
+ }
23730
23735
 
23731
23736
  export default nextConfig
23732
23737
  `;
@@ -24207,20 +24212,34 @@ async function runSeed() {
24207
24212
  p9.cancel("No auth.config.ts found. Run: npx aegis-auth init first.");
24208
24213
  process.exit(1);
24209
24214
  }
24210
- console.log(
24211
- `
24212
- ${import_chalk12.default.dim("This creates the first user account in your database.")}
24213
- `
24214
- );
24215
+ const hasPrisma = import_fs_extra5.default.existsSync(import_path5.default.join(cwd, "node_modules", ".prisma", "client"));
24216
+ if (!hasPrisma) {
24217
+ p9.cancel("Prisma client not generated. Run: npx prisma generate first.");
24218
+ process.exit(1);
24219
+ }
24220
+ console.log(`
24221
+ ${import_chalk12.default.dim("Creates the first user account in your database.")}
24222
+ `);
24215
24223
  const role = await p9.text({
24216
- message: "Role ID to seed",
24224
+ message: "Role ID",
24217
24225
  placeholder: "admin",
24218
24226
  validate: (v) => !v ? "Required" : void 0
24219
24227
  });
24220
24228
  if (p9.isCancel(role)) process.exit(0);
24229
+ const loginField = await p9.select({
24230
+ message: "Login field for this role",
24231
+ options: [
24232
+ { value: "email", label: "email" },
24233
+ { value: "username", label: "username" }
24234
+ ]
24235
+ });
24236
+ if (p9.isCancel(loginField)) process.exit(0);
24221
24237
  const identifier = await p9.text({
24222
- message: "Email or username",
24223
- validate: (v) => !v ? "Required" : void 0
24238
+ message: loginField === "email" ? "Email address" : "Username",
24239
+ validate: (v) => {
24240
+ if (!v) return "Required";
24241
+ if (loginField === "email" && !v.includes("@")) return "Enter a valid email address";
24242
+ }
24224
24243
  });
24225
24244
  if (p9.isCancel(identifier)) process.exit(0);
24226
24245
  const password3 = await p9.password({
@@ -24228,25 +24247,50 @@ async function runSeed() {
24228
24247
  validate: (v) => v.length < 8 ? "At least 8 characters" : void 0
24229
24248
  });
24230
24249
  if (p9.isCancel(password3)) process.exit(0);
24231
- console.log();
24232
- console.log(
24233
- ` ${import_chalk12.default.yellow("\u26A0")} ${import_chalk12.default.dim("Seed functionality requires your app to be running with Prisma connected.")}`
24234
- );
24235
- console.log(
24236
- ` ${import_chalk12.default.dim("Add this to a script in your project or run via ts-node:")}`
24237
- );
24238
- console.log();
24239
- console.log(
24240
- import_chalk12.default.dim(
24241
- ` import { PrismaClient } from '@prisma/client'
24242
- import { hashPassword } from '@alinsafawi/aegis-auth-core'
24243
- const prisma = new PrismaClient()
24244
- await prisma.${role}.create({
24245
- data: { email: '${identifier}', passwordHash: await hashPassword('${password3}') }
24246
- })`
24247
- )
24248
- );
24249
- console.log();
24250
+ const spin = p9.spinner();
24251
+ spin.start("Creating user\u2026");
24252
+ try {
24253
+ const envPath = import_path5.default.join(cwd, ".env");
24254
+ if (import_fs_extra5.default.existsSync(envPath)) {
24255
+ const raw = import_fs_extra5.default.readFileSync(envPath, "utf8");
24256
+ for (const line of raw.split("\n")) {
24257
+ const trimmed = line.trim();
24258
+ if (!trimmed || trimmed.startsWith("#")) continue;
24259
+ const eq = trimmed.indexOf("=");
24260
+ if (eq === -1) continue;
24261
+ const key = trimmed.slice(0, eq).trim();
24262
+ const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
24263
+ if (!process.env[key]) process.env[key] = val;
24264
+ }
24265
+ }
24266
+ const { PrismaClient } = require(import_path5.default.join(cwd, "node_modules", ".prisma", "client"));
24267
+ const { hashPassword } = require(import_path5.default.join(cwd, "node_modules", "@alinsafawi", "aegis-auth-core", "dist", "index.js"));
24268
+ const prisma = new PrismaClient();
24269
+ const modelKey = role.charAt(0).toLowerCase() + role.slice(1);
24270
+ const passwordHash = await hashPassword(password3);
24271
+ await prisma[modelKey].create({
24272
+ data: {
24273
+ [loginField]: identifier,
24274
+ passwordHash
24275
+ }
24276
+ });
24277
+ await prisma.$disconnect();
24278
+ spin.stop(`${import_chalk12.default.green("\u2713")} User created`);
24279
+ console.log();
24280
+ console.log(` ${import_chalk12.default.bold("Role")} ${import_chalk12.default.magentaBright(role)}`);
24281
+ console.log(` ${import_chalk12.default.bold(loginField)} ${import_chalk12.default.cyan(identifier)}`);
24282
+ console.log();
24283
+ } catch (err) {
24284
+ spin.stop(`${import_chalk12.default.red("\u2717")} Failed`);
24285
+ console.log();
24286
+ if (err?.code === "P2002") {
24287
+ console.log(` ${import_chalk12.default.red("A user with that ${loginField} already exists.")}`);
24288
+ } else {
24289
+ console.log(` ${import_chalk12.default.red(err?.message ?? String(err))}`);
24290
+ }
24291
+ console.log();
24292
+ process.exit(1);
24293
+ }
24250
24294
  }
24251
24295
 
24252
24296
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alinsafawi/aegis-auth",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "The shield your Next.js app deserves — full-stack auth in minutes",
5
5
  "bin": {
6
6
  "aegis-auth": "dist/index.js"