Tips for properly configuring a session with everyauth and express

I've been working on a simple nodejs application that allows users to log in with Facebook using express and everyauth. I followed the instructions provided in the README tutorial here and set up my app.js file as shown below:

var everyauth = require('everyauth');

everyauth.facebook
    .appId('829428097067274')
    .appSecret('2c4d4a96514aa8374fbc54d611945148')
    .findOrCreateUser(function (session, accessToken, accessTokExtra, fbUserMetadata) {
        // Actual logic for user creation will be added later

        console.log("in find or create user")

        console.log(session); // always undefined
        console.log(accessToken);
        console.log(accessTokExtra);
        console.log(fbUserMetadata);

        return { id: 100, session: "the session" }; // uncertain about what to return here
    })
    .redirectPath('/');

// express.session() no longer works due to package changes
// Unsure which package should replace it
// app.use(express.session());

app.use(everyauth.middleware(app));

Upon launching the app, I navigate to localhost:3000/auth/facebook, which correctly redirects me to Facebook for authorization. After authorizing the app, I am redirected back to localhost:3000/auth/facebook/callback where I encounter an error message:

Step getSession of facebook

 is promising: session; however, the step returns nothing. Fix the step by returning the expected values OR by returning a Promise that promises said values.

I'm unsure of my mistake in this implementation. Can anyone provide guidance?

Answer №1

Even though it's getting late, let's discuss a common struggle I faced with both everyauth and express 4.x.

If you're working with express 4.x, make sure to add express-session using npm install express-session

In the code snippet below, you can see how some parts are similar to the example provided by everyauth.

var session = require('express-session');
...
var app = express();
app.use(session({secret : "anything you want"}));
app.use(everyauth.middleware());

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

Template not found: Error encountered in nodemailer-express-handlebars: ENOENT: The specified file or directory does not exist in the node

I've been attempting to utilize nodemailer and express-handlebars in my node.js application to send a template form. However, I keep encountering the "no such file" error. Unfortunately, I have no clue what I'm overlooking or missing. Here is m ...

Transferring binary data from C# to Node.js for deserialization

I am facing a challenge where I have a byte array created in C# from an object type, which is then sent over the socket protocol to a Node.js app. However, I am unable to deserialize the data into a readable object. Can anyone suggest a way to decode this ...

The conclusion of a promise/then chain is not determined by the return statement

Below is the code snippet used for signing up users: const pgp = require('pg-promise')(); const crypto = require('./crypto.js'); const db = pgp(connection); const querySelect = (text, params) => { const s = pgp.as.format(text, ...

What is the process for using Discriminators, the Mongo DB API, and Mongoose to insert data into Cosmos DB?

Issue Overview I am currently facing a challenge in writing documents to my Cosmos DB using the Mongo DB API and Mongoose for Object Modeling. To optimize costs, I aim to store all documents in a single collection by utilizing Discriminators. The project ...

What are the steps to initiate a new project using the CLI on a Linux operating system

I've got a project up and running in Vue JS with Node JS installed. Now I want to create a new project using CLI. Do I need to install another version of Node JS for this new project? ...

5 Creative Techniques for Manipulating Boolean Variables in If Statements

I am receiving a unique custom header value and the values I am getting are accurate. The expected values include: true, false, undefined. However, the response associated with the value: false is incorrect. Code Snippet let deviceStatus = req.headers[ ...

Update the message displayed in the user interface after the view has been fully rendered in an Express application, following the execution of asynchronous

I have created a simple express app that reads files from a directory, renames them, zips the files asynchronously, and then renders another view. The file reading and renaming are done synchronously, while the zipping part is handled asynchronously. My cu ...

Is AngularJS primarily a client-side or server-side framework, or does it have elements

Is it possible to connect to the database on the server side? I have experience using it on the client side, but can the same method be used on the server side? If it's not suitable for server-side use, should I go with PHP or Node.js for designing ...

Warning: The parameter type in the Node JS project is not compatible with the argument type

Upon running this code in WebStorm, I encountered a warning: Argument type {where: {email: userData.emil}} is not assignable to parameter type NonNullFindOptions<Model["_attributes"]> Can someone explain this warning to me? This project ...

Encountering an issue with resolving the Vite html loader file error

During my project using Vite, I encountered an error when running npm run dev, displaying the message: Failed to scan for dependencies from entries: <path>/Learning/Vite-test/index.html [ERROR] No loader is configured for ".html" files: in ...

Guide to using a JavaScript client-side app to interact with MongoDB using Node.js

Picture this scenario: In one hand, you have server #1 in our Datacenter with MongoDB, nodejs, and a Node.js script that can read and write to MongoDB. In the other hand, there's server #2 with nginx/apache running a web app for displaying MongoDB da ...

At what point is the JavaScript function expression triggered in this code snippet?

let express = require('express') let app = express(); app.use(express.static('static')); let server = app.listen(3000, function() { let port = server.address().port; console.log("The server has started on port", port); }); I ...

Troubleshooting in VS Code with Mocha and hitting a breakpoint that halts at the 'read-only inlined content from source map' file

Yes, yes, I understand. Current VS Code version is 1.25.1 Mocha version: 4.0.1 Mocha running through launch.json: { "name": "mocha", "protocol": "inspector", "type": "node", "request": "launch", "program": "${workspaceRoot}/node_modu ...

Node.js module fails to return a value

I encountered an issue while trying to access a model function inside a controller in my Node.js application. The function is returning undefined. Below is a snippet of my code: userController.js file var User = require('../models/user'); ...

Encountering issues with the Sequelize Model.prototype.(customFunction) feature malfunctioning

While attempting to define a customFunction within the Sequelize model, I encountered an error: TypeError: user.getJWT is not a function at User.create.then (/projects/test/a/app/controllers/UserController.js:22:29) Below is the code snippet from ...

Is it possible to create an API directly within the URL of a React.js application, similar to how Next.js allows?

When using Next.js, I can access my application on localhost:3000, and also access my API from localhost:3000/api/hello. I'm curious if there is a way to achieve this same setup with React.js and another framework like Express.js? If Next.js is not ...

Missing data: Node JS fails to recognize req.body

I've looked through various posts and I'm feeling quite lost with this issue. When I run console.log(req), the output is as follows: ServerResponse { ... req: IncomingMessage { ... url: '/my-endpoint', method: &a ...

I encountered an issue while trying to start my Nuxt project - facing difficulty in resolving 'fsevents' within the project directory

Whenever I start my nuxt.js project using npm run dev, I encounter compilation errors: × Client Compiled with some errors in 12.53s WARN Compiled with 2 warnings ...

Error in uploading files with Node.js, Multer, and Angular - issue with setting headers after they have already been sent

Working with Angular 5, Node.js, and Multer to upload a file. The process involves first saving the file to a directory and then inserting the path into the database. To begin, I created a form: <input type="file" (change)="onFileSelected($event)"> ...

What is the most effective method for nesting loops in NodeJS and Mocha?

Currently, I am attempting to create a loop within a loop in my NodeJS code, but I seem to be getting lost along the way. The results are not as expected - sometimes callbacks are triggered twice and so on. My approach involves using the async module. I wo ...