@warlock.js/auth 4.6.1 → 4.7.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.
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { environment, rootPath } from "@warlock.js/core";
|
|
2
2
|
import { Random } from "@mongez/reinforcements";
|
|
3
3
|
import { log } from "@warlock.js/logger";
|
|
4
|
-
import {
|
|
4
|
+
import { fs } from "@warlock.js/fs";
|
|
5
5
|
|
|
6
6
|
//#region ../@warlock.js/auth/src/services/generate-jwt-secret.ts
|
|
7
7
|
async function generateJWTSecret() {
|
|
8
8
|
let envFile = rootPath(".env");
|
|
9
9
|
log.info("jwt", "generating", "Generating JWT secrets");
|
|
10
10
|
const environmentMode = environment();
|
|
11
|
-
if (!await
|
|
12
|
-
if (!await
|
|
11
|
+
if (!await fs.files.exists(envFile)) envFile = rootPath(environmentMode === "production" ? ".env.production" : ".env.development");
|
|
12
|
+
if (!await fs.files.exists(envFile)) {
|
|
13
13
|
log.error("jwt", "error", ".env file not found");
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
let contents = await
|
|
16
|
+
let contents = await fs.files.get(envFile);
|
|
17
17
|
const hasJwtSecret = contents.includes("JWT_SECRET");
|
|
18
18
|
const hasJwtRefreshSecret = contents.includes("JWT_REFRESH_SECRET");
|
|
19
19
|
if (hasJwtSecret && hasJwtRefreshSecret) {
|
|
@@ -39,7 +39,7 @@ JWT_REFRESH_SECRET=${jwtRefreshSecret}
|
|
|
39
39
|
} else log.info("jwt", "exists", "JWT_REFRESH_SECRET already exists in the .env file.");
|
|
40
40
|
if (secretsToAdd) {
|
|
41
41
|
contents += secretsToAdd;
|
|
42
|
-
await
|
|
42
|
+
await fs.files.put(envFile, contents);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-jwt-secret.mjs","names":[],"sources":["../../../../../../../@warlock.js/auth/src/services/generate-jwt-secret.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"generate-jwt-secret.mjs","names":[],"sources":["../../../../../../../@warlock.js/auth/src/services/generate-jwt-secret.ts"],"sourcesContent":["import { fs } from \"@warlock.js/fs\";\nimport { Random } from \"@mongez/reinforcements\";\nimport { environment, rootPath } from \"@warlock.js/core\";\nimport { log } from \"@warlock.js/logger\";\n\nexport async function generateJWTSecret() {\n let envFile = rootPath(\".env\");\n\n log.info(\"jwt\", \"generating\", \"Generating JWT secrets\");\n\n const environmentMode = environment();\n\n if (!(await fs.files.exists(envFile))) {\n const envFileType = environmentMode === \"production\" ? \".env.production\" : \".env.development\";\n envFile = rootPath(envFileType);\n }\n\n if (!(await fs.files.exists(envFile))) {\n log.error(\"jwt\", \"error\", \".env file not found\");\n return;\n }\n\n let contents = await fs.files.get(envFile);\n\n const hasJwtSecret = contents.includes(\"JWT_SECRET\");\n const hasJwtRefreshSecret = contents.includes(\"JWT_REFRESH_SECRET\");\n\n if (hasJwtSecret && hasJwtRefreshSecret) {\n log.warn(\"jwt\", \"exists\", \"JWT secrets already exist in the .env file.\");\n return;\n }\n\n let secretsToAdd = \"\";\n\n if (!hasJwtSecret) {\n const jwtSecret = Random.token(32);\n secretsToAdd += `\n# JWT Secret\nJWT_SECRET=${jwtSecret}\n`;\n log.success(\"jwt\", \"generated\", \"JWT_SECRET generated and added to the .env file.\");\n } else {\n log.info(\"jwt\", \"exists\", \"JWT_SECRET already exists in the .env file.\");\n }\n\n if (!hasJwtRefreshSecret) {\n const jwtRefreshSecret = Random.token(32);\n secretsToAdd += `\n# JWT Refresh Secret\nJWT_REFRESH_SECRET=${jwtRefreshSecret}\n`;\n log.success(\"jwt\", \"generated\", \"JWT_REFRESH_SECRET generated and added to the .env file.\");\n } else {\n log.info(\"jwt\", \"exists\", \"JWT_REFRESH_SECRET already exists in the .env file.\");\n }\n\n if (secretsToAdd) {\n contents += secretsToAdd;\n await fs.files.put(envFile, contents);\n }\n}\n"],"mappings":";;;;;;AAKA,eAAsB,oBAAoB;CACxC,IAAI,UAAU,SAAS,MAAM;CAE7B,IAAI,KAAK,OAAO,cAAc,wBAAwB;CAEtD,MAAM,kBAAkB,YAAY;CAEpC,IAAI,CAAE,MAAM,GAAG,MAAM,OAAO,OAAO,GAEjC,UAAU,SADU,oBAAoB,eAAe,oBAAoB,kBAC7C;CAGhC,IAAI,CAAE,MAAM,GAAG,MAAM,OAAO,OAAO,GAAI;EACrC,IAAI,MAAM,OAAO,SAAS,qBAAqB;EAC/C;CACF;CAEA,IAAI,WAAW,MAAM,GAAG,MAAM,IAAI,OAAO;CAEzC,MAAM,eAAe,SAAS,SAAS,YAAY;CACnD,MAAM,sBAAsB,SAAS,SAAS,oBAAoB;CAElE,IAAI,gBAAgB,qBAAqB;EACvC,IAAI,KAAK,OAAO,UAAU,6CAA6C;EACvE;CACF;CAEA,IAAI,eAAe;CAEnB,IAAI,CAAC,cAAc;EACjB,MAAM,YAAY,OAAO,MAAM,EAAE;EACjC,gBAAgB;;aAEP,UAAU;;EAEnB,IAAI,QAAQ,OAAO,aAAa,kDAAkD;CACpF,OACE,IAAI,KAAK,OAAO,UAAU,6CAA6C;CAGzE,IAAI,CAAC,qBAAqB;EACxB,MAAM,mBAAmB,OAAO,MAAM,EAAE;EACxC,gBAAgB;;qBAEC,iBAAiB;;EAElC,IAAI,QAAQ,OAAO,aAAa,0DAA0D;CAC5F,OACE,IAAI,KAAK,OAAO,UAAU,qDAAqD;CAGjF,IAAI,cAAc;EAChB,YAAY;EACZ,MAAM,GAAG,MAAM,IAAI,SAAS,QAAQ;CACtC;AACF"}
|
package/package.json
CHANGED
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"ms": "^2.1.3"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@warlock.js/fs": "4.
|
|
27
|
-
"@warlock.js/cache": "4.
|
|
28
|
-
"@warlock.js/cascade": "4.
|
|
29
|
-
"@warlock.js/core": "4.
|
|
30
|
-
"@warlock.js/logger": "4.
|
|
31
|
-
"@warlock.js/seal": "4.
|
|
26
|
+
"@warlock.js/fs": "4.7.0",
|
|
27
|
+
"@warlock.js/cache": "4.7.0",
|
|
28
|
+
"@warlock.js/cascade": "4.7.0",
|
|
29
|
+
"@warlock.js/core": "4.7.0",
|
|
30
|
+
"@warlock.js/logger": "4.7.0",
|
|
31
|
+
"@warlock.js/seal": "4.7.0"
|
|
32
32
|
},
|
|
33
|
-
"version": "4.
|
|
33
|
+
"version": "4.7.0",
|
|
34
34
|
"type": "module",
|
|
35
35
|
"main": "./esm/index.mjs",
|
|
36
36
|
"module": "./esm/index.mjs",
|