Coder Social home page Coder Social logo

mernprojectecommerce's People

Contributors

meabhisingh avatar zeeshanejaz786 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mernprojectecommerce's Issues

Search/Filer Optimization Postman Returning False

image

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.

forgot password error

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??

Overlay navbar error using react-icons

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'

Server returning 401 unauthorized using axios

image

This is my userActions.js after executing the login although data is returned but still shows unauthorized

image
but here the yellow highlighted part shows that data is given but still not reaching redux

Proxy error

I got proxy error in my project.I am at
Screenshot (5)
taching my screenshot of error please help regard this.

Forgot Password Verification (Postman)

image
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"

Deploy Your App

Deploy your app somewhere, so that we can visit it and get motivated to build it

Redux state not updating

My redux state of products is not updating , the action is however dispatched and i can log it on my console but the redux toolkit shows that that state is empty. please help me with this

image

image

image

Regarding Overlay-Navbar

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.

"app-crashed --waiting for file changes before starting..."how to fix it

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..."

Forgot Password Error

{
"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);

Problem while using React Icons in overlay Navbar during starting of the frontend .

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'

Forgot password

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

Pagination not working

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

Resource not found. Invalid : _id

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)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.