Apollo Express does not include the Express Passport Session feature

After integrating my express server with passport for user authentication on our portal, there seemed to be an issue when trying to fetch user details from our API using the same session from the client. While I could see identity provider data for the logged-in user, GraphQL calls made from the React side did not have the user session in their request to Apollo servers, despite it being present in the Express session.

I followed the steps outlined in the Apollo Server documentation, but encountered difficulties when setting up the context for ApolloServer as the 'req' object did not contain passport in its session.

     // Code snippet showing the integration of express server and Apollo Server with passport authentication
    

Answer №1

Ensure that the request includes sending the session cookies. I encountered a similar issue while using Graphql Playground as the client, which by default disables sending cookies. To resolve this, access the settings located in the top right corner of the playground and adjust the

"request.credentials": "same-origin"
. Once implemented, the passport session should initialize correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching the endpoint renders the middleware ineffective

I've encountered a puzzling issue with my NodeJs - Express server, which serves as the backend for my mobile application. The problem arises when I send post requests to certain endpoints like checkmail and checkusername using axios from the frontend ...

Retrieve the route.js directory using Node.js

My server.js file is located in the directory: /dir1. To start the server, I use the command node server.js. In the directory /dir1/app/, I have my file named routes.js. I am trying to find out the directory path of the server.js file. However, I am unc ...

Error encountered when attempting to populate nested fields in Mongoose

Recently, I encountered an error while trying to add comments to my posts by using nested populate for mongoose. Initially, everything was working fine when I only pre-populated user data. However, as soon as I implemented nested populate, I started receiv ...

Struggling to locate the proper documentation for the next() function

There are multiple ways in which the next() method can be utilized: next(), next('route'), next(error)... Where is the official documentation for the next() method located? I have not been able to find a comprehensive explanation of its use cas ...

When utilizing multer for handling multipart data, hasOwnProperty appears to become undefined

Below is the code snippet I am currently working with: var express = require('express'); var mongoose = require('mongoose'); var bodyParser = require('body-parser'); var multer = require('multer'); var user = requir ...

Setting up Socket.io results in numerous transport polling GET requests being initiated

I have set up an express.js server-side and followed the socket.io guide. However, I am facing issues with the socket connection not being successful, and there seems to be a high number of unexpected GET requests like this: https://i.stack.imgur.com/GDGg ...

Unable to download file from Express using res.download in Angular

Within my application, I am generating a file on the backend and then attempting to provide it to the user for download via a browser. Despite multiple attempts, I have been unable to achieve this. Below is the code snippet for the express backend: app.g ...

The functionality of Everyauth seems to be malfunctioning in the latest version of Express

Currently, I am utilizing nodejs, express 4, and everyauth for social network authentication. I have encountered an issue where upon clicking Accept from Google and getting redirected back to my /, an error message appears: _http_outgoing.js:335 throw ne ...

Webpack bundling causes NodeJS application to lose track of modules

Currently, I am in the process of developing a node/express server that needs to be bundled for deployment on an IIS server. This particular server is specifically for backend processes. Upon attempting to execute the code post-bundling, I encountered the ...

AWS lambda not properly displaying static content for an Angular application when running Node Express server

Recently, I encountered an issue while trying to deploy my Angular application on AWS Lambda. I kept receiving a 403 exception for my static content, even though I used Express.js to configure the server. You can check out the problems I'm facing at t ...

Can you explain the significance of "var router = require('./router/main')(app)"?

(I came across a similar question on stackoverflow, but I'm having trouble understanding the comments..) Hello, I am a middle school student from Korea. English is not my strong suit, so please bear with me. Currently, I am learning Node.js and Expr ...

What is the process for implementing a new requirement for 'confirmed' users when they log in with passport.js?

Looking to enhance the functionality of passport.js by implementing a conditional check to verify if the user account is confirmed. The plan is to insert an 'if statement' towards the end of the code, right after validating the user's email ...

What is the best way to send an array of objects to a Jade template?

I'm looking to retrieve an array of objects from MongoDB and pass it to the client... Here is an example object: var objeto_img= { name:'name of the file', ...

Preventing the creation of several Sequelize class instances

As I work on constructing a basic database schema using Express and Sequelize, I've organized my models in separate files. In a central file called models/index.js, I initialize an instance of the Sequelize class, import the models, and define relatio ...

What steps should I take to enable a route guard to authenticate a token once it has been stored in local storage?

I'm currently working on a basic login page with authentication using Angular and Express. Here's what I've got so far: a login component a service that handles http requests and stores the jwt token in local storage a route guard for the ...

Unable to make a POST request to the express API using the next.js API route (nextauth)

Currently, I have an express server running on port 8080 and my NextJS app running on port 3000. To handle user authentication, I am utilizing nextauth which involves sending username and password credentials to the express API on port 8080 for validation. ...

Node.js communicates using commas instead of newlines

Whenever I use Express to generate a project, it outputs commas instead of newlines. For example: express my_project This generates everything in a single line ,/**, * Module dependencies., */,,var express = require('express'), , routes = ...

Using a REST API to make a POST request that calls a function and passes

Within my index.js file, the following code is implemented: app.post("/token", function (req, res) { var token = req.body createToken(token); }); This functionality is then exported by token.js const createToken = (token) = (req, res) => ...

When navigating from the "add" page to the "show listing" page in Node.js, the most recent input

When I redirect from adding data in my code, it does not fetch the latest data. However, when I refresh the page, it retrieves the updated information. var CountryResponseData = []; router.get('/', ensureAuthenticated, (req, res) =>{ Coun ...

Executing a function in Node-Express with a database connection at the beginning of the application

I am relatively new to Node.js and currently working on a Node.js - Express solution as a back-end for an AngularJS web application. My goal is to send an email when the MSSQL database query returns specific information. I have successfully implemented thi ...