Next.js 13 Full Stack E-commerce App #25 | Authorize Roles on API Routes, Create New Product
Вставка
- Опубліковано 11 тра 2023
- Git Repo Link:
github.com/ghulamabbas2/buyit...
Checkout my In-Depth Next.js Masterclass on Udemy Courses:
www.udemy.com/course/nextjs-b...
Next.js 13 Authentication with Next-Auth:
• Next.js Authentication...
================================================================
⚙️ Gadgets I use for Recording:
💻 Laptop - Macbook PRO M1 - 16/512
amzn.to/4eUqrSe
🎤 MIC - Samson Technologies Q2U USB/XLR Dynamic Microphone
amzn.to/3W9Z4wl
🖱️Mouse - Logitech G402 Gaming Mouse Hyperion Fury USB, Black
amzn.to/3RY4xUy
⌨️ Keyboard - Logitech K380 Multi-Device Bluetooth Keyboard
amzn.to/3RY4Fn0
🖥️ Monitor - UltraSharp 24-Inch Screen Led-Lit Monitor (U2419H)
amzn.to/4bxidN6
================================================================
Welcome back to our Next.js 13 Full Stack E-commerce App series! In this episode, we'll be covering two important topics: authorizing roles on API routes and creating new products.
First, we'll dive into how to secure your API routes by authorizing roles. We'll show you how to set up middleware to check the user's role before allowing them to access protected endpoints. This is an essential step in keeping your e-commerce platform secure and preventing unauthorized access to sensitive data.
Next, we'll walk you through the process of creating a new product for your online store. We'll cover the necessary code and APIs needed to add a new product to your database and display it on your site.
LIKE, SHARE & SUBSCRIBE!
As usual, thanks mate.
const [product, setProduct] = useState({
name: "",
description: "",
seller: "",
price: "",
stock: "",
category: "Electronics", // Set the default value to "Electronics"
});
Do this if you get a statuscode 400 error when sending the Product to backend it makes sure the category field is not left empty and set electronics as default. even if you don't open the category dropdown to select a category.
❤️ thanks boss❤️
why doesn't the newProduct function work, even though I followed the video tutorial, can you help me?
Hi Ghulam! So, I ran into a problem that I could not resolve, even after going through the video 3 times and checking all the changed files:
'POST 400 (Bad Request) */api/admin/products '
I got so frustrated that I even tried with your repo from this video, changing the 'next.config' file for mine and I'm still getting the same error. Just to be clear, this is also happening with your repo at this stage (026-new-product) -do you have any idea why this might be? (I checked the db and the product is not added.
Thanks again!
Hello Abbas and Terry, I have the same issue with POST api/admin/products, any suggestions, please
@@akhror-oshie Have you had any luck solving this yet? This is driving me crazy, especially as it's in the teacher's code too.
@@TerryMitchell haha)) not yet, bro. I switched to another project and waiting for the teacher's response
@@akhror-oshie Still no feedback, right? I'm thinking of testing his repo for #26 to see if he's resolved this error before I invest more time in studying it - I'll let you know how I get on.
I can say the problem persists even with Abbas' new repo which is really strange - I'm not sure how to proceed if even the tutor's code isn't working. I'm wondering if it's our operating system as nobody else appears to be having this problem - are you using Linux by any chance?
After debugging further I see the product posting fails inside productControllers > newProduct()
- I can successfully console log req.body.user = req.user._id;
but it fails at Product.create()
- even in Abbas' repo - is nobody else having this problem? (I think people are just waiting for the course to finish and use the code :( )
Looking forward to your next videos