meabhisingh / mernprojectecommerce Goto Github PK
View Code? Open in Web Editor NEWThis is MERN Stack Ecommerce Project Made to Teach MERN Stack on YouTube
This is MERN Stack Ecommerce Project Made to Teach MERN Stack on YouTube
utils/apifeature.js
class ApiFeatures {
constructor(query, queryStr) {
this.query = query;
this.queryStr = queryStr;
}
search() {
const keyword = this.queryStr.keyword
? {
name: {
$regex: this.queryStr.keyword,
$options: "i",
},
}
: {};
this.query = this.query.find({ ...keyword });
return this;
}
filter(){
const queryCopy = {...this.queryStr}
console.log(queryCopy)
//REMOVE SOME FIELDS
const removeFields = ["keyword","page","limit"];
removeFields.forEach(key=>delete queryCopy[key])
this.query = this.query.find(queryCopy)
}
}
module.exports = ApiFeatures;
controllers/productController.js
//GET PRODUCT DETAILS
`exports.getProductDetails = catchAsyncErrors(async(req,res,next)=>{
const product = await Product.findById(req.params.id)
if(!product){
return next(new ErrorHandler("Product Not Found",404))
}
res.status(200).json({
success:true,
product
})
})`
Help me over this error. I'm using the same code from GitHub files but postman is returning Success: False with error as Query cannot read properties.
Video Mark 7:07 when we try to remove --> pagination while Filter <----
Facing this error with the new react version. Any solution?
I am stuck at user authentication part. If someone can help me out I'll be more than helpful๐
while I'm sending a post request in postman it is giving me the following error.....
{
"success": false,
message: "Illegal arguments: undefined, number"
}
is this error due to email??
http://localhost:3000/process/payment page is not loading it is showing error on the code below
{stripeApiKey && isAuthenticated && (
<Route exact path="/process/payment" element={} />
)}
ERROR in ./node_modules/react-icons/all.js 4:0-22
The requested module './io5' contains conflicting star exports for the names 'IoLogoAndroid', 'IoLogoAngular', 'IoLogoApple', 'IoLogoBitbucket', 'IoLogoBitcoin', 'IoLogoBuffer', 'IoLogoChrome', 'IoLogoClosedCaptioning', 'IoLogoCodepen', 'IoLogoCss3', 'IoLogoDesignernews', 'IoLogoDribbble', 'IoLogoDropbox', 'IoLogoEuro', 'IoLogoFacebook', 'IoLogoFlickr', 'IoLogoFoursquare', 'IoLogoGithub', 'IoLogoGoogle', 'IoLogoHackernews', 'IoLogoHtml5', 'IoLogoInstagram', 'IoLogoIonic', 'IoLogoIonitron', 'IoLogoJavascript', 'IoLogoLinkedin', 'IoLogoMarkdown', 'IoLogoNoSmoking', 'IoLogoNodejs', 'IoLogoNpm', 'IoLogoOctocat', 'IoLogoPinterest', 'IoLogoPlaystation', 'IoLogoPython', 'IoLogoReddit', 'IoLogoRss', 'IoLogoSass', 'IoLogoSkype', 'IoLogoSlack', 'IoLogoSnapchat', 'IoLogoSteam', 'IoLogoTumblr', 'IoLogoTux', 'IoLogoTwitch', 'IoLogoTwitter', 'IoLogoUsd', 'IoLogoVimeo', 'IoLogoVk', 'IoLogoWhatsapp', 'IoLogoWindows', 'IoLogoWordpress', 'IoLogoXbox', 'IoLogoXing', 'IoLogoYahoo', 'IoLogoYen', 'IoLogoYoutube' with the previous requested module './io'
Hello Sir,
I am getting issue in register time
RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
same issue in your server too
https://mern-stack-ecommerce-store.herokuapp.com/login
Can you help?
There is a issue when user is not login or register. The errors: GET http://localhost:3000/api/me 401 (Unauthorized) and GET http://localhost:3000/api/stripeapikey 401 (Unauthorized)
I need a help with this error.
POP & IMAP is enabled on the email that I am using with this forgot password verification but I'm not able to send mail through smtp.
sendEmail.js
const nodeMailer = require("nodemailer");
const sendEmail = async (options)=>{
const transporter = nodeMailer.createTransport({
service: process.env.SMPT_SERVICE,
auth: {
user: process.env.SMPT_MAIL,
pass: process.env.SMPT_PASSWORD,
},
});
const mailOptions = {
from: process.env.SMPT_MAIL,
to: options.email,
subject: options.subject,
text: options.message,
};
await transporter.sendMail(mailOptions);
};
module.exports = sendEmail;
userController.js
//FORGOT PASSWORD
exports.forgotPassword = catchAsyncErrors(async (req, res, next) => {
const user = await User.findOne({ email: req.body.email });
if (!user) {
return next(new ErrorHander("User not found", 404));
}
// Get ResetPassword Token
const resetToken = user.getResetPasswordToken();
await user.save({ validateBeforeSave: false });
const resetPasswordUrl = `${req.protocol}://${req.get(
"host"
)}/password/reset/${resetToken}`;
const message = `Your password reset token is :- \n\n ${resetPasswordUrl} \n\nIf you have not requested this email then, please ignore it.`;
try {
await sendEmail({
email: user.email,
subject: `Ecommerce Password Recovery`,
message,
});
res.status(200).json({
success: true,
message: `Email sent to ${user.email} successfully`,
});
} catch (error) {
user.resetPasswordToken = undefined;
user.resetPasswordExpire = undefined;
await user.save({ validateBeforeSave: false });
return next(new ErrorHander(error.message, 500));
}
});
config.env
SMPT_SERVICE="gmail"
SMPT_MAIL="[email protected]"
SMPT_PASSWORD="password"
please help me i sort out params and images problem now stuck in this new problem help me plz
Deploy your app somewhere, so that we can visit it and get motivated to build it
i am not getting cookies in chrome but i am getting cookies in postman please help anyone.......
The overlay navbar does not collapse on itself when we click any link in it. Due to this we cannot know that click actually worked until we cut the overlay navbar by ourselves.
With react and react dom 18 react alert is not working. need help
Hello,
I get an issue call:
{"success":false,"message":"ENOENT: no such file or directory, stat 'F:\MERN tutorials\PROJECTS\mernProjectEcommerce\frontend\build\index.html'"}
every time my code is working fine but after few second it is showing ""
"const serverSelectionError = new ServerSelectionError();
^
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at Connection.openUri (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\connection.js:825:32)
at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:417:10
at C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise ()
at promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:1270:10)
at Mongoose.connect (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongoose\lib\index.js:416:20)
at connectDatabase (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\config\database.js:5:6)
at Object. (C:\Users\Amit Rao\Desktop\MERN PROJECT\backend\server.js:10:1)
at Module._compile (node:internal/modules/cjs/loader:1218:14) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'localhost:27017' => ServerDescription {
address: 'localhost:27017',
type: 'Unknown',
hosts: [],
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 6053295,
lastWriteDate: 0,
error: MongoNetworkError: connect ECONNREFUSED ::1:27017
at connectionFailureError (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:387:20)
at Socket. (C:\Users\Amit Rao\Desktop\MERN PROJECT\node_modules\mongodb\lib\cmap\connect.js:310:22)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
cause: Error: connect ECONNREFUSED ::1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1283:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 27017
},
[Symbol(errorLabels)]: Set(1) { 'ResetPool' }
},
topologyVersion: null,
setName: null,
setVersion: null,
electionId: null,
logicalSessionTimeoutMinutes: null,
primary: null,
me: null,
'$clusterTime': null
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}
Node.js v19.2.0
[nodemon] app crashed - waiting for file changes before starting..."
error in postman shows this
{
"success": false,
"message": "Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials k23-20020a63d857000000b0051b595b26adsm4865559pgj.91 - gsmtp"
}
{
"success": false,
"message": "Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials m13-20020a654c8d000000b0041c35462316sm14850184pgt.26 - gsmtp"
}
I Am getting this error
Config file
`JWT_SECRET = "ASDFJSDKFJSDVLKSDJFKLSDJFLKSDJDFLKSD"
JWT_EXPIRE = 5d
COOKIE_EXPIRE = 5
SMTP_SERVICE = "gmail"
SMTP_MAIL = "[email protected]"
SMTP_PASSWORD = "12345678"
SMTP_HOST = smtp.gmail.com
SMTP_PORT = 465`
sendEmail.js file
`const nodeMailer = require("nodemailer");
const sendEmail = async (options) => {
const transporter = nodeMailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT,
service: process.env.SMTP_SERVICE,
auth: {
user: process.env.SMTP_MAIL,
pass: process.env.SMTP_PASSWORD,
},
});
const mailOptions = {
from: process.env.SMTP_MAIL,
to: options.email,
subject: options.subject,
text: options.message,
};
await transporter.sendMail(mailOptions);
};
module.exports = sendEmail;`
userController forgotPassword.js
`// Forgot Password
exports.forgotPassword = catchAsyncErrors(async (req, res, next) => {
const user = await User.findOne({ email: req.body.email });
if (!user) {
return next(new ErrorHandler("User not found", 404));
}
// Get ResetPassword Token
const resetToken = user.getResetPasswordToken();
await user.save({ validateBeforeSave: false });
const resetPasswordUrl = `${req.protocol}://${req.get(
"host"
)}/password/reset/${resetToken}`;
const message = `Your password reset token is :- \n\n ${resetPasswordUrl} \n\nIf you have not requested this email then, please ignore it.`;
try {
await sendEmail({
email: user.email,
subject: `Ecommerce Password Recovery`,
message,
});
res.status(200).json({
success: true,
message: `Email sent to ${user.email} successfully`,
});
} catch (error) {
user.resetPasswordToken = undefined;
user.resetPasswordExpire = undefined;
await user.save({ validateBeforeSave: false });
return next(new ErrorHandler(error.message, 500));
}
});`
Route
router.route("/password/forgot").post(forgotPassword);
If someone has successfully migrated from stripe to Indian payment gateway. Please do link your GitHub link over here . Any help would be appreciated ๐
ERROR in ./node_modules/react-icons/all.js 4:0-22
The requested module './io5' contains conflicting star exports for the names 'IoLogoAndroid', 'IoLogoAngular', 'IoLogoApple', 'IoLogoBitbucket', 'IoLogoBitcoin', 'IoLogoBuffer', 'IoLogoChrome', 'IoLogoClosedCaptioning', 'IoLogoCodepen', 'IoLogoCss3', 'IoLogoDesignernews', 'IoLogoDribbble', 'IoLogoDropbox', 'IoLogoEuro', 'IoLogoFacebook', 'IoLogoFlickr', 'IoLogoFoursquare', 'IoLogoGithub', 'IoLogoGoogle', 'IoLogoHackernews', 'IoLogoHtml5', 'IoLogoInstagram', 'IoLogoIonic', 'IoLogoIonitron', 'IoLogoJavascript', 'IoLogoLinkedin', 'IoLogoMarkdown', 'IoLogoNoSmoking', 'IoLogoNodejs', 'IoLogoNpm', 'IoLogoOctocat', 'IoLogoPinterest', 'IoLogoPlaystation', 'IoLogoPython', 'IoLogoReddit', 'IoLogoRss', 'IoLogoSass', 'IoLogoSkype', 'IoLogoSlack', 'IoLogoSnapchat', 'IoLogoSteam', 'IoLogoTumblr', 'IoLogoTux', 'IoLogoTwitch', 'IoLogoTwitter', 'IoLogoUsd', 'IoLogoVimeo', 'IoLogoVk', 'IoLogoWhatsapp', 'IoLogoWindows', 'IoLogoWordpress', 'IoLogoXbox', 'IoLogoXing', 'IoLogoYahoo', 'IoLogoYen', 'IoLogoYoutube' with the previous requested module './io'
Hello.. I am facing an issue while working on User Registration & Profile Update. I am getting JS alert as "INTERNAL SERVER ERROR" as i click on REGISTER & UPDATE PROFILE buttons.
Can someone help me with this... @meabhisingh
In user controller forgot password function containing
await user.save({ validateBeforeSave: false });
This line of code is not work and throw error undefine and number
And when i comment out this line then it work properly but then :token in user route give error token expired
How can i solve it
It seems like req.user.role
is not working here. But I couldn't figure out exact issue. Can anyone please help me?
In productDetails page i am not able to get the product details due to match.params.id
please tell me how to fix this issue because match does not work with latest react
The pagination component is not working as its not switching and the 1 and 2 options are not coming as per your code
this is the code:
import React, { Fragment, useEffect, useState } from 'react'
import "./Products.css"
import { useSelector, useDispatch } from 'react-redux'
import { clearErrors, getProduct } from '../../actions/productAction'
import Loader from '../layout/Loader/Loader'
import ProductCard from '../Home/ProductCard'
import Pagination from "react-js-pagination"
import { useAlert } from 'react-alert'
function Products({ match }) {
const dispatch = useDispatch();
const [currentPage, setCurrentPage] = useState(1);
const { products, loading, error, productsCount, resultPerPage } = useSelector((state) => state.products);
const keyword = match.params.keyword;
const setCurrentPageNo = (e) => {
setCurrentPage(e);
}
useEffect(() => {
dispatch(getProduct(keyword, currentPage));
}, [dispatch, keyword, currentPage])
return (
<Fragment>
{loading ? (<Loader />) : (
<Fragment>
<h2 className='productsHeading'>Products</h2>
<div className="products">
{products &&
products.map((product) => (
<ProductCard key={product._id} product={product} />
))}
</div>
<div className="paginationBox">
<Pagination
activePage={match.params.page}
itemsCountPerPage={resultPerPage}
totalItemsCount={productsCount}
onChange={setCurrentPageNo}
nextPageText="Next"
prevPageText="Prev"
firstPageText="1st"
lastPageText="Last"
itemClass="page-item"
linkClass="page-link"
activeClass="active"
activeLinkClass="pageLinkActive"
/>
</div>
</Fragment>
)}
</Fragment>
)
}
export default Products
the Pagination links are failing to switch and its only showing 1st prev next and last...1 and 2 are not there
How to make the sliders smooth ?
import ReviewCard from "./ReviewCard.js";
import { useParams } from 'react-router-dom'
const ProductDetails = () => {
const [open, setOpen] = React.useState(true);
const { params } = useParams()
const dispatch = useDispatch();
useEffect(() => {
dispatch(getProductDetails(params?.id))
}, [dispatch, params?.id])
const { product, loading, error } = useSelector(
(state) => state?.productDetails
);
**I am getting error 'Resource not found. Invalid: _id when try to navigate on a product detail from home page by selecting a product.**
I have already use CastError in error.js
//Wrong Mongodb id error
if (err.name === 'CastError') {
const message = `Resource not found. Invalid : ${err.path}`;
err = new ErrorHandler(message, 400)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.