nest-authme 1.1.0 → 1.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.
- package/dist/cli.js +93 -11
- package/dist/cli.js.map +1 -1
- package/dist/generator/templates/entities/user.entity.typeorm.hbs +21 -1
- package/dist/generator/templates/guards/github-auth.guard.ts.hbs +5 -0
- package/dist/generator/templates/guards/google-auth.guard.ts.hbs +5 -0
- package/dist/generator/templates/jwt/auth.controller.ts.hbs +57 -1
- package/dist/generator/templates/jwt/auth.module.ts.hbs +22 -0
- package/dist/generator/templates/jwt/auth.service.ts.hbs +151 -1
- package/dist/generator/templates/mail/mail.module.ts.hbs +10 -0
- package/dist/generator/templates/mail/mail.service.ts.hbs +71 -0
- package/dist/generator/templates/prisma/schema.prisma.additions.hbs +13 -1
- package/dist/generator/templates/shared/README.auth.md.hbs +9 -0
- package/dist/generator/templates/shared/env.hbs +25 -0
- package/dist/generator/templates/shared/env.template.hbs +25 -0
- package/dist/generator/templates/strategies/github.strategy.ts.hbs +33 -0
- package/dist/generator/templates/strategies/google.strategy.ts.hbs +33 -0
- package/dist/generator/templates/tests/auth.service.spec.ts.hbs +72 -0
- package/dist/generator/templates/users/users.service.ts.hbs +105 -0
- package/dist/gui/gui.html +49 -0
- package/dist/gui/index.js +54 -11
- package/dist/gui/index.js.map +1 -1
- package/dist/gui/orchestrator.d.ts +7 -0
- package/dist/gui/orchestrator.js +36 -0
- package/dist/gui/orchestrator.js.map +1 -1
- package/dist/gui/server.js +54 -11
- package/dist/gui/server.js.map +1 -1
- package/dist/index.js +82 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -322,6 +322,41 @@ async function promptConfig(detectedORM, detectedDB) {
|
|
|
322
322
|
message: "Enable forgot/reset password?",
|
|
323
323
|
default: true
|
|
324
324
|
},
|
|
325
|
+
{
|
|
326
|
+
type: "confirm",
|
|
327
|
+
name: "enableAccountLockout",
|
|
328
|
+
message: "Enable account lockout after failed login attempts?",
|
|
329
|
+
default: false
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
type: "confirm",
|
|
333
|
+
name: "enableEmailService",
|
|
334
|
+
message: "Enable email service (Nodemailer) for sending emails?",
|
|
335
|
+
default: false,
|
|
336
|
+
when: (answers2) => answers2.enableEmailVerification || answers2.enableResetPassword
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
type: "confirm",
|
|
340
|
+
name: "enableOAuth",
|
|
341
|
+
message: "Enable OAuth2 social login (Google, GitHub)?",
|
|
342
|
+
default: false
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
type: "checkbox",
|
|
346
|
+
name: "oauthProviders",
|
|
347
|
+
message: "Select OAuth providers:",
|
|
348
|
+
choices: [
|
|
349
|
+
{ name: "Google", value: "google", checked: true },
|
|
350
|
+
{ name: "GitHub", value: "github", checked: true }
|
|
351
|
+
],
|
|
352
|
+
when: (answers2) => answers2.enableOAuth,
|
|
353
|
+
validate: (input) => {
|
|
354
|
+
if (input.length === 0) {
|
|
355
|
+
return "Please select at least one provider";
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
},
|
|
325
360
|
{
|
|
326
361
|
type: "confirm",
|
|
327
362
|
name: "useDetectedORM",
|
|
@@ -365,6 +400,10 @@ function getDefaultAnswers(_detectedORM, detectedDB) {
|
|
|
365
400
|
useUsername: false,
|
|
366
401
|
enableEmailVerification: false,
|
|
367
402
|
enableResetPassword: true,
|
|
403
|
+
enableAccountLockout: false,
|
|
404
|
+
enableEmailService: false,
|
|
405
|
+
enableOAuth: false,
|
|
406
|
+
oauthProviders: [],
|
|
368
407
|
useDetectedORM: true,
|
|
369
408
|
database: detectedDB || "postgres",
|
|
370
409
|
autoInstall: true
|
|
@@ -388,13 +427,19 @@ function buildConfig(answers, projectName, sourceRoot, detectedORM, detectedDB)
|
|
|
388
427
|
unitTests: answers.generateTests,
|
|
389
428
|
useUsername: answers.useUsername,
|
|
390
429
|
emailVerification: answers.enableEmailVerification,
|
|
391
|
-
resetPassword: answers.enableResetPassword
|
|
430
|
+
resetPassword: answers.enableResetPassword,
|
|
431
|
+
accountLockout: answers.enableAccountLockout,
|
|
432
|
+
emailService: answers.enableEmailService
|
|
392
433
|
},
|
|
393
434
|
jwt: {
|
|
394
435
|
secret: generateSecret(),
|
|
395
436
|
accessExpiration: answers.accessExpiration,
|
|
396
437
|
refreshExpiration: answers.refreshExpiration || "7d"
|
|
397
438
|
},
|
|
439
|
+
oauth: answers.enableOAuth ? {
|
|
440
|
+
google: (answers.oauthProviders || []).includes("google"),
|
|
441
|
+
github: (answers.oauthProviders || []).includes("github")
|
|
442
|
+
} : void 0,
|
|
398
443
|
autoInstall: answers.autoInstall,
|
|
399
444
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
400
445
|
generatorVersion: "1.3.0"
|
|
@@ -663,6 +708,18 @@ var init_generator = __esm({
|
|
|
663
708
|
{ template: "jwt/jwt-auth.guard.ts.hbs", output: `${config.sourceRoot}/auth/guards/jwt-auth.guard.ts` },
|
|
664
709
|
{ template: "jwt/local-auth.guard.ts.hbs", output: `${config.sourceRoot}/auth/guards/local-auth.guard.ts` }
|
|
665
710
|
);
|
|
711
|
+
if (config.oauth?.google) {
|
|
712
|
+
plan.push(
|
|
713
|
+
{ template: "strategies/google.strategy.ts.hbs", output: `${config.sourceRoot}/auth/strategies/google.strategy.ts` },
|
|
714
|
+
{ template: "guards/google-auth.guard.ts.hbs", output: `${config.sourceRoot}/auth/guards/google-auth.guard.ts` }
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
if (config.oauth?.github) {
|
|
718
|
+
plan.push(
|
|
719
|
+
{ template: "strategies/github.strategy.ts.hbs", output: `${config.sourceRoot}/auth/strategies/github.strategy.ts` },
|
|
720
|
+
{ template: "guards/github-auth.guard.ts.hbs", output: `${config.sourceRoot}/auth/guards/github-auth.guard.ts` }
|
|
721
|
+
);
|
|
722
|
+
}
|
|
666
723
|
if (config.rbac.enabled) {
|
|
667
724
|
plan.push(
|
|
668
725
|
{ template: "rbac/roles.guard.ts.hbs", output: `${config.sourceRoot}/auth/guards/roles.guard.ts` },
|
|
@@ -709,6 +766,12 @@ var init_generator = __esm({
|
|
|
709
766
|
{ template: "prisma/schema.prisma.additions.hbs", output: "prisma-schema-additions.prisma" }
|
|
710
767
|
);
|
|
711
768
|
}
|
|
769
|
+
if (config.features.emailService) {
|
|
770
|
+
plan.push(
|
|
771
|
+
{ template: "mail/mail.module.ts.hbs", output: `${config.sourceRoot}/mail/mail.module.ts` },
|
|
772
|
+
{ template: "mail/mail.service.ts.hbs", output: `${config.sourceRoot}/mail/mail.service.ts` }
|
|
773
|
+
);
|
|
774
|
+
}
|
|
712
775
|
if (config.features.unitTests) {
|
|
713
776
|
plan.push(
|
|
714
777
|
{ template: "tests/auth.service.spec.ts.hbs", output: `${config.sourceRoot}/auth/auth.service.spec.ts` },
|
|
@@ -781,6 +844,9 @@ var init_ast_updater = __esm({
|
|
|
781
844
|
} else if (config && config.orm === "prisma") {
|
|
782
845
|
this.addImport("./prisma/prisma.module", ["PrismaModule"]);
|
|
783
846
|
}
|
|
847
|
+
if (config && config.features.emailService) {
|
|
848
|
+
this.addImport("./mail/mail.module", ["MailModule"]);
|
|
849
|
+
}
|
|
784
850
|
this.addImport("./auth/auth.module", ["AuthModule"]);
|
|
785
851
|
this.addImport("./users/users.module", ["UsersModule"]);
|
|
786
852
|
}
|
|
@@ -849,6 +915,9 @@ var init_ast_updater = __esm({
|
|
|
849
915
|
} else if (config && config.orm === "prisma" && !existingModules.has("PrismaModule")) {
|
|
850
916
|
allElements.push("PrismaModule");
|
|
851
917
|
}
|
|
918
|
+
if (config && config.features.emailService && !existingModules.has("MailModule")) {
|
|
919
|
+
allElements.push("MailModule");
|
|
920
|
+
}
|
|
852
921
|
if (!existingModules.has("AuthModule")) {
|
|
853
922
|
allElements.push("AuthModule");
|
|
854
923
|
}
|
|
@@ -1196,6 +1265,18 @@ var init_package_updater = __esm({
|
|
|
1196
1265
|
if (config.features.swagger) {
|
|
1197
1266
|
dependencies["@nestjs/swagger"] = "^11.0.0";
|
|
1198
1267
|
}
|
|
1268
|
+
if (config.oauth?.google) {
|
|
1269
|
+
dependencies["passport-google-oauth20"] = "^2.0.0";
|
|
1270
|
+
devDependencies["@types/passport-google-oauth20"] = "^2.0.14";
|
|
1271
|
+
}
|
|
1272
|
+
if (config.oauth?.github) {
|
|
1273
|
+
dependencies["passport-github2"] = "^0.1.12";
|
|
1274
|
+
devDependencies["@types/passport-github2"] = "^1.2.9";
|
|
1275
|
+
}
|
|
1276
|
+
if (config.features.emailService) {
|
|
1277
|
+
dependencies["nodemailer"] = "^6.9.0";
|
|
1278
|
+
devDependencies["@types/nodemailer"] = "^6.4.0";
|
|
1279
|
+
}
|
|
1199
1280
|
return { dependencies, devDependencies };
|
|
1200
1281
|
}
|
|
1201
1282
|
/**
|
|
@@ -1554,22 +1635,23 @@ data: ${JSON.stringify(data)}
|
|
|
1554
1635
|
this.sendJson(res, 404, { error: "Not found" });
|
|
1555
1636
|
}
|
|
1556
1637
|
handleGetIndex(res) {
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1638
|
+
const candidates = [
|
|
1639
|
+
path6.join(__dirname, "gui.html"),
|
|
1640
|
+
path6.join(__dirname, "gui", "gui.html"),
|
|
1641
|
+
path6.join(__dirname, "..", "dist", "gui", "gui.html"),
|
|
1642
|
+
path6.join(__dirname, "..", "src", "gui", "gui.html")
|
|
1643
|
+
];
|
|
1644
|
+
for (const candidate of candidates) {
|
|
1564
1645
|
try {
|
|
1565
|
-
const html = fs8.readFileSync(
|
|
1646
|
+
const html = fs8.readFileSync(candidate, "utf-8");
|
|
1566
1647
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
1567
1648
|
res.end(html);
|
|
1649
|
+
return;
|
|
1568
1650
|
} catch {
|
|
1569
|
-
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
1570
|
-
res.end("GUI HTML file not found. Please rebuild with: npm run build");
|
|
1571
1651
|
}
|
|
1572
1652
|
}
|
|
1653
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
1654
|
+
res.end("GUI HTML file not found. Please rebuild with: npm run build");
|
|
1573
1655
|
}
|
|
1574
1656
|
async handleGetProject(res) {
|
|
1575
1657
|
try {
|