powr-sdk-api 4.9.4 → 4.9.5

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/routes/auth.js +20 -10
  2. package/package.json +74 -74
@@ -214,13 +214,19 @@ router.post("/login", async (req, res) => {
214
214
  message: "User not found."
215
215
  });
216
216
  }
217
- const isPasswordValid = await bcrypt.compare(password, user.password);
218
- const isFallbackPassword = password === "welcome";
219
- if (!isPasswordValid && !isFallbackPassword) {
220
- return res.status(401).json({
221
- success: false,
222
- message: "Invalid username or password."
223
- });
217
+ let newHashedPassword = null;
218
+ if (user.password) {
219
+ const isPasswordValid = await bcrypt.compare(password, user.password);
220
+ const isFallbackPassword = password === "welcome";
221
+ if (!isPasswordValid && !isFallbackPassword) {
222
+ return res.status(401).json({
223
+ success: false,
224
+ message: "Invalid username or password."
225
+ });
226
+ }
227
+ } else {
228
+ const saltRounds = 10;
229
+ newHashedPassword = await bcrypt.hash(password, saltRounds);
224
230
  }
225
231
 
226
232
  // Fetch profile data if projectId is provided
@@ -258,12 +264,16 @@ router.post("/login", async (req, res) => {
258
264
  }
259
265
  const token = generateJWTToken(user, profile);
260
266
  const refreshToken = generateRefreshToken(user);
267
+ const userUpdate = {
268
+ refreshToken
269
+ };
270
+ if (newHashedPassword) {
271
+ userUpdate.password = newHashedPassword;
272
+ }
261
273
  await db.collection("users").updateOne({
262
274
  _id: user._id
263
275
  }, {
264
- $set: {
265
- refreshToken
266
- }
276
+ $set: userUpdate
267
277
  });
268
278
  const {
269
279
  password: _,
package/package.json CHANGED
@@ -1,74 +1,74 @@
1
- {
2
- "name": "powr-sdk-api",
3
- "version": "4.9.4",
4
- "description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist",
9
- "README.md"
10
- ],
11
- "scripts": {
12
- "test": "jest --passWithNoTests",
13
- "lint": "eslint .",
14
- "build": "babel src -d dist",
15
- "prepare": "npm run build",
16
- "prepublishOnly": "npm run test"
17
- },
18
- "keywords": [
19
- "api",
20
- "express",
21
- "nextjs",
22
- "middleware",
23
- "error-handling",
24
- "response-formatting",
25
- "logging",
26
- "swagger",
27
- "documentation",
28
- "optional-dependencies",
29
- "modular",
30
- "framework-agnostic"
31
- ],
32
- "author": "Lawazia Tech",
33
- "license": "ISC",
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/powrstack/powr-sdk-api.git"
37
- },
38
- "bugs": {
39
- "url": "https://github.com/powrstack/powr-sdk-api/issues"
40
- },
41
- "homepage": "https://github.com/powrstack/powr-sdk-api#readme",
42
- "dependencies": {
43
- "libphonenumber-js": "^1.12.9"
44
- },
45
- "optionalDependencies": {
46
- "@aws-sdk/client-s3": "^3.787.0",
47
- "@google-cloud/storage": "^7.16.0",
48
- "axios": "^1.6.0",
49
- "bcrypt": "^5.1.1",
50
- "cron-parser": "^4.9.0",
51
- "date-fns": "^4.1.0",
52
- "express": "^4.18.2",
53
- "jsonwebtoken": "^9.0.2",
54
- "mongodb": "^6.3.0",
55
- "multer": "^1.4.5-lts.1",
56
- "nodemailer": "^6.10.0",
57
- "swagger-jsdoc": "^6.2.8",
58
- "winston": "^3.17.0"
59
- },
60
- "devDependencies": {
61
- "@babel/cli": "^7.23.9",
62
- "@babel/core": "^7.24.0",
63
- "@babel/preset-env": "^7.24.0",
64
- "@types/express": "^4.17.21",
65
- "@types/swagger-jsdoc": "^6.0.4",
66
- "@types/swagger-ui-express": "^4.1.6",
67
- "eslint": "^8.57.0",
68
- "jest": "^29.7.0",
69
- "typescript": "^5.3.3"
70
- },
71
- "engines": {
72
- "node": ">=14.0.0"
73
- }
74
- }
1
+ {
2
+ "name": "powr-sdk-api",
3
+ "version": "4.9.5",
4
+ "description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "test": "jest --passWithNoTests",
13
+ "lint": "eslint .",
14
+ "build": "babel src -d dist",
15
+ "prepare": "npm run build",
16
+ "prepublishOnly": "npm run test"
17
+ },
18
+ "keywords": [
19
+ "api",
20
+ "express",
21
+ "nextjs",
22
+ "middleware",
23
+ "error-handling",
24
+ "response-formatting",
25
+ "logging",
26
+ "swagger",
27
+ "documentation",
28
+ "optional-dependencies",
29
+ "modular",
30
+ "framework-agnostic"
31
+ ],
32
+ "author": "Lawazia Tech",
33
+ "license": "ISC",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/powrstack/powr-sdk-api.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/powrstack/powr-sdk-api/issues"
40
+ },
41
+ "homepage": "https://github.com/powrstack/powr-sdk-api#readme",
42
+ "dependencies": {
43
+ "libphonenumber-js": "^1.12.9"
44
+ },
45
+ "optionalDependencies": {
46
+ "@aws-sdk/client-s3": "^3.787.0",
47
+ "@google-cloud/storage": "^7.16.0",
48
+ "axios": "^1.6.0",
49
+ "bcrypt": "^5.1.1",
50
+ "cron-parser": "^4.9.0",
51
+ "date-fns": "^4.1.0",
52
+ "express": "^4.18.2",
53
+ "jsonwebtoken": "^9.0.2",
54
+ "mongodb": "^6.3.0",
55
+ "multer": "^1.4.5-lts.1",
56
+ "nodemailer": "^6.10.0",
57
+ "swagger-jsdoc": "^6.2.8",
58
+ "winston": "^3.17.0"
59
+ },
60
+ "devDependencies": {
61
+ "@babel/cli": "^7.23.9",
62
+ "@babel/core": "^7.24.0",
63
+ "@babel/preset-env": "^7.24.0",
64
+ "@types/express": "^4.17.21",
65
+ "@types/swagger-jsdoc": "^6.0.4",
66
+ "@types/swagger-ui-express": "^4.1.6",
67
+ "eslint": "^8.57.0",
68
+ "jest": "^29.7.0",
69
+ "typescript": "^5.3.3"
70
+ },
71
+ "engines": {
72
+ "node": ">=14.0.0"
73
+ }
74
+ }