blog-server | 基于koa2的服务端 , vue的后台管理系统 | Authentication library
kandi X-RAY | blog-server Summary
kandi X-RAY | blog-server Summary
基于koa2的服务端,vue的后台管理系统
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of blog-server
blog-server Key Features
blog-server Examples and Code Snippets
Community Discussions
Trending Discussions on blog-server
QUESTION
I have a MERN stack blog app that I'm making as a learning exercise. I'm relatively comfortable on the front end but have limited experience in node. I'm adding authentification after following a couple tutorials to get this far. I'm using passport.js as a framework to make a request to Google, get back an id and save as session info. However, after logging in, req.session is empty when making a post request, even though I can see a cookie in the dev tools.
I'm using bcrypt's hash to obscure the actual id, but that may not be best practice.
in blogAuth.js: req.session is defined.
bcrypt.hash(req.user._id.toString(), saltRounds, function(err, hash) {
req.session.user = hash;
//session is set here.
console.log(req.session); res.redirect(
http://localhost:8080/articles/loggedIn);
});
but in api/articles.js: req.session is empty
router.post("/", (req, res, next) => {
const { body } = req;
// session is empty here. Why?
console.log(
Session user, ${req.session.user});
console.log(req.session);
I have tried:
Including proxy in the client package.json: express req.session empty with cookie-session
using withCredentials set to true when sending the POST from the client:Node + Express + Passport: req.user Undefined
Rearranging the order of middleware: Routes must always come afterward, but I feel like I'm doing this blindly and it usually results in an error
Here's some of the relevant files:
Server side: - app.js - blogAuth.js - passport.js - api/articles.js
Client side: - the POST req
I believe this is an issue with ordering. What is a good way to ensure that I order my middleware correctly? Or if the order looks correct, where else could this issue becoming from?
...ANSWER
Answered 2018-Nov-18 at 07:43You are trying to use cookie-session
as well as express-session
. Since both of them will try to control the fate of req.session
object, you will end up with empty session always.
Just remove one of them, and your session will be persisted.
QUESTION
I'm new to redux and followed this tutorial to create a simple blog app with react and redux. I've completed it, however I noticed that componentWillRecieveProps
is being deprecated. I'm trying to replace it with more up-to-date code, but have been unable to understand how to do so. I've read this article about replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’, but I don't think that this is the correct use for getDerivedStateFromProps as React's blog post on replacing one with the other describes.
My current componentWillRecieveProps
code:
ANSWER
Answered 2018-Oct-19 at 04:35componentWillReceiveProps() method is deprecated by introducing a new life cycle method called getDerivedStateFromProps().
Keep in mind that you should always compare current props with previous props like below and if they both are not same then do setState otherwise you will get into infinite setState warning
Replace below code in place of componentWillReceiveProps method
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install blog-server
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page