powr-sdk-api 2.4.4 → 2.4.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.
- package/dist/routes/auth.js +14 -9
- package/package.json +1 -1
package/dist/routes/auth.js
CHANGED
|
@@ -128,7 +128,8 @@ router.post("/login", async (req, res) => {
|
|
|
128
128
|
}]
|
|
129
129
|
};
|
|
130
130
|
console.log(q);
|
|
131
|
-
const
|
|
131
|
+
const db = await getDb();
|
|
132
|
+
const user = await db.collection("users").findOne(q);
|
|
132
133
|
console.log(user);
|
|
133
134
|
if (!user) {
|
|
134
135
|
return res.status(401).json({
|
|
@@ -147,13 +148,13 @@ router.post("/login", async (req, res) => {
|
|
|
147
148
|
// Fetch profile data if projectId is provided
|
|
148
149
|
let profile = null;
|
|
149
150
|
if (projectId) {
|
|
150
|
-
profile = await
|
|
151
|
+
profile = await db.collection("profiles").findOne({
|
|
151
152
|
userId: user._id,
|
|
152
153
|
projectId: projectId
|
|
153
154
|
});
|
|
154
155
|
if (profile) {
|
|
155
156
|
// Update lastActiveAt
|
|
156
|
-
await
|
|
157
|
+
await db.collection("profiles").updateOne({
|
|
157
158
|
_id: profile._id
|
|
158
159
|
}, {
|
|
159
160
|
$set: {
|
|
@@ -168,7 +169,7 @@ router.post("/login", async (req, res) => {
|
|
|
168
169
|
createdAt: new Date(),
|
|
169
170
|
updatedAt: new Date()
|
|
170
171
|
};
|
|
171
|
-
const profileResult = await
|
|
172
|
+
const profileResult = await db.collection("profiles").insertOne(newProfile);
|
|
172
173
|
profile = {
|
|
173
174
|
_id: profileResult.insertedId,
|
|
174
175
|
...newProfile
|
|
@@ -226,7 +227,8 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
226
227
|
message: "Username is required"
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
|
-
const
|
|
230
|
+
const db = await getDb();
|
|
231
|
+
const user = await db.collection("users").findOne({
|
|
230
232
|
username: username
|
|
231
233
|
});
|
|
232
234
|
if (!user) {
|
|
@@ -243,7 +245,7 @@ router.post("/forgot-password", async (req, res) => {
|
|
|
243
245
|
exp: Math.floor(Date.now() / 1000) + 60 * 60
|
|
244
246
|
};
|
|
245
247
|
const resetToken = jwt.sign(resetPayload, config.jwtToken);
|
|
246
|
-
await
|
|
248
|
+
await db.collection("users").updateOne({
|
|
247
249
|
_id: user._id
|
|
248
250
|
}, {
|
|
249
251
|
$set: {
|
|
@@ -294,7 +296,8 @@ router.post("/reset-password", async (req, res) => {
|
|
|
294
296
|
message: "Invalid reset token type or missing user ID"
|
|
295
297
|
});
|
|
296
298
|
}
|
|
297
|
-
const
|
|
299
|
+
const db = await getDb();
|
|
300
|
+
const user = await db.collection("users").findOne({
|
|
298
301
|
_id: new ObjectId(decoded.userId),
|
|
299
302
|
resetToken: resetToken,
|
|
300
303
|
resetTokenExpiry: {
|
|
@@ -311,7 +314,9 @@ router.post("/reset-password", async (req, res) => {
|
|
|
311
314
|
// Hash the new password
|
|
312
315
|
const saltRounds = 10;
|
|
313
316
|
const hashedPassword = await bcrypt.hash(newPassword, saltRounds);
|
|
314
|
-
|
|
317
|
+
|
|
318
|
+
// Update user with new password and clear reset token
|
|
319
|
+
await db.collection("users").updateOne({
|
|
315
320
|
_id: user._id
|
|
316
321
|
}, {
|
|
317
322
|
$set: {
|
|
@@ -327,7 +332,7 @@ router.post("/reset-password", async (req, res) => {
|
|
|
327
332
|
message: "Password reset successfully"
|
|
328
333
|
});
|
|
329
334
|
} catch (error) {
|
|
330
|
-
console.error("Error
|
|
335
|
+
console.error("Error in reset password:", error);
|
|
331
336
|
return res.status(500).json({
|
|
332
337
|
success: false,
|
|
333
338
|
message: "Failed to reset password."
|