express

session not create after login using passport .js

人走茶凉 提交于 2020-06-28 04:13:09
问题 i use console.log(user.id) in serialize it show user id when i login but in browser when i go in application, session storage is empty. it not show any key and value Passport.js const LocalStrategy = require('passport-local').Strategy const mongoose = require('mongoose') const bcrypt = require('bcrypt') const User = require('../models/User') module.exports = function(passport) { passport.use("local", new LocalStrategy({usernameField:"email"}, (email, password, done)=>{ User.findOne({email

React axios multiple files upload

别来无恙 提交于 2020-06-28 04:11:29
问题 I'm trying upload multiple images with axios in React but i cannot figure out what is wrong. First I tried to upload single image and that work just fine. But with multiple images I'm out of options. I'm creating FormData like so: for (let i = 0; i < images.length; i++) { formData.append('productPhotos[' + i + ']', images[i]); } The axios request looking like this const config = { headers: { 'Content-Type': 'multipart/form-data' } }; axios .post(endPoints.createProduct, formData, config)

Cast to ObjectId failed for value at path for model error

ぐ巨炮叔叔 提交于 2020-06-28 03:38:53
问题 This is my Profile Schema: const mongoose = require('mongoose'); const ProfileSchema = new mongoose.Schema({ user: { // Special field type because // it will be associated to different user type: mongoose.Schema.Types.ObjectId, ref: 'user', }, company: { type: String, }, website: { type: String, }, location: { type: String, }, status: { type: String, required: true, }, skills: { type: [String], required: true, }, bio: { type: String, }, githubusername: { type: String, }, experience: [ { title

Cast to ObjectId failed for value at path for model error

安稳与你 提交于 2020-06-28 03:38:48
问题 This is my Profile Schema: const mongoose = require('mongoose'); const ProfileSchema = new mongoose.Schema({ user: { // Special field type because // it will be associated to different user type: mongoose.Schema.Types.ObjectId, ref: 'user', }, company: { type: String, }, website: { type: String, }, location: { type: String, }, status: { type: String, required: true, }, skills: { type: [String], required: true, }, bio: { type: String, }, githubusername: { type: String, }, experience: [ { title

Every time React sends request to Express, a new session is generated

别来无恙 提交于 2020-06-27 12:59:05
问题 I use React as a client to send request to Express with proxy and express-session set up. But every time React makes a request to Express server, a new session is created. So I checked Express alone by manually accessing to the same api url and it keep using the same session each time I refresh the page. Project structure: project-folder - client // React client with proxy set up + src + package.json + ... - server.js - package.json Inside server.js : const session = require('express-session'

Express session is empty in Safari

南楼画角 提交于 2020-06-27 11:03:39
问题 I'm building a Node.js application with express. I use express-session for sessions. The data I store in a session is available in IE, Chrome and Firefox. But in Safari the session is empty all the time. So when I do console.log(req.session) it prints: Session { cookie: { path: '/', _expires: null, originalMaxAge: null, httpOnly: true, secure: true }, userHasCheckCorrect: true } This are my settings in server.js app.use(session({ secret: process.env.SESSION_SECRET, resave: false,

Express session is empty in Safari

社会主义新天地 提交于 2020-06-27 11:02:21
问题 I'm building a Node.js application with express. I use express-session for sessions. The data I store in a session is available in IE, Chrome and Firefox. But in Safari the session is empty all the time. So when I do console.log(req.session) it prints: Session { cookie: { path: '/', _expires: null, originalMaxAge: null, httpOnly: true, secure: true }, userHasCheckCorrect: true } This are my settings in server.js app.use(session({ secret: process.env.SESSION_SECRET, resave: false,

Get only IPv4 ips via NodeJS express

允我心安 提交于 2020-06-27 10:01:07
问题 I have a NodeJS express service running on Centos and listens to GET requests and I need to identify the IP of the user. Currently, I'm using this script ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress The problem is that sometimes the IP returned is IPv4 and sometimes it is IPv6. Is there a way to get only IPv4 IPs? 回答1: Update Base on Micheal's comment, if client is connected via ipv6 there will not be an

typescript error - cannot find name 'process'

↘锁芯ラ 提交于 2020-06-27 07:03:20
问题 I am setting up a new project with express+ typescript and facing typescript error - cann't find name 'processs' package.json "dependencies": { "express": "^4.16.4", "nodemon": "^1.18.7", "tsc": "^1.20150623.0", "typescript": "^3.1.6" }, "devDependencies": { "@types/express": "^4.16.0", "@types/mocha": "^5.2.5", "@types/node": "^10.12.10", "eslint": "^5.9.0", "eslint-config-airbnb-base": "^13.1.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-promise": "^4.0.1", "mocha": "^5.2.0",

aws-serverless-express connection error - EPIPE

别来无恙 提交于 2020-06-27 03:55:10
问题 We have a NodeJS 10.16.3 Express API. We've recently switched from AWS Elastic Beanstalk/EC2 to Lambda / Serverless. Our DB is Postgres (PostgreSQL) 12.2. It seemed all of a sudden I started getting this error on my local server when making requests from the client: offline: ANY /dev/inventory/inventory (λ: app) ERROR: aws-serverless-express connection error { Error: write EPIPE at WriteWrap.afterWrite (net.js:788:14) errno: 'EPIPE', code: 'EPIPE', syscall: 'write' } offline: (λ: app)