Compare commits

...

2 Commits

Author SHA1 Message Date
pawan-dot
8f6e52813d password forgot api change 2025-05-08 13:12:38 +05:30
pawan-dot
af107e6845 password forgot api change 2025-05-08 12:44:17 +05:30
4 changed files with 32 additions and 23 deletions

View File

@ -1,6 +1,11 @@
import admin from "firebase-admin"; import admin from "firebase-admin";
import { readFileSync } from "fs";
// import serviceAccount from "../googlefirebasePushnotification.json" with { type: "json" }; // import serviceAccount from "../googlefirebasePushnotification.json" with { type: "json" };
import serviceAccount from "../googlefirebasePushnotification.json" assert { type: "json" }; // import serviceAccount from "../googlefirebasePushnotification.json" assert { type: "json" };
const serviceAccount = JSON.parse(
readFileSync("./googlefirebasePushnotification.json", "utf8")
);
export const sendPushNotification = async (userToken, title, message) => { export const sendPushNotification = async (userToken, title, message) => {
// const admin = require("firebase-admin"); // const admin = require("firebase-admin");
// const serviceAccount = require("./path/to/your-firebase-adminsdk.json"); // const serviceAccount = require("./path/to/your-firebase-adminsdk.json");

6
app.js
View File

@ -7,12 +7,16 @@ import bodyParser from "body-parser";
import fileUpload from "express-fileupload"; // important pkg for file upload import fileUpload from "express-fileupload"; // important pkg for file upload
import cors from "cors"; import cors from "cors";
import cookieParser from "cookie-parser"; import cookieParser from "cookie-parser";
import { readFileSync } from "fs";
// firebase admin push notification // firebase admin push notification
import admin from "firebase-admin"; import admin from "firebase-admin";
// import serviceAccount from "./googlefirebasePushnotification.json" with { type: "json" }; // import serviceAccount from "./googlefirebasePushnotification.json" with { type: "json" };
import serviceAccount from "./googlefirebasePushnotification.json" assert { type: "json" }; // import serviceAccount from "./googlefirebasePushnotification.json" assert { type: "json" };
// Design Router // Design Router
const serviceAccount = JSON.parse(
readFileSync("./googlefirebasePushnotification.json", "utf8")
);
import designRoute from "./resources/Design/designRouter.js"; import designRoute from "./resources/Design/designRouter.js";
app.use(express.json({ limit: "50mb" })); app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ extended: true, limit: "50mb" })); app.use(express.urlencoded({ extended: true, limit: "50mb" }));

View File

@ -620,10 +620,10 @@ export const forgotPassword = async (req, res, next) => {
return res.status(404).json({ message: "User not found" }); return res.status(404).json({ message: "User not found" });
} }
// Get ResetPassword Token // Get ResetPassword Token
const resetToken = user.getResetPasswordToken(); //call function // const resetToken = user.getResetPasswordToken(); //call function
//save database reset token //save database reset token
await user.save({ validateBeforeSave: false }); // await user.save({ validateBeforeSave: false });
const passwords = password.randomPassword({ const passwords = password.randomPassword({
length: 12, length: 12,
@ -653,10 +653,10 @@ export const forgotPassword = async (req, res, next) => {
message: `Email sent to ${user.email} successfully`, message: `Email sent to ${user.email} successfully`,
}); });
} catch (error) { } catch (error) {
user.resetPasswordToken = undefined; // user.resetPasswordToken = undefined;
user.resetPasswordExpire = undefined; // user.resetPasswordExpire = undefined;
await user.save({ validateBeforeSave: false }); // await user.save({ validateBeforeSave: false });
return res return res
.status(500) .status(500)
@ -732,10 +732,10 @@ export const ResetPasswordAdmin = async (req, res) => {
} catch (error) { } catch (error) {
console.error("Error resetting password:", error); console.error("Error resetting password:", error);
console.error(error);
res.status(500).json({ res.status(500).json({
success: false, message: error?.message || "Something went wrong!",
message: error: error?.message || "",
error.message || "Something went wrong while resetting the password.",
}); });
} }
}; };