S
S
Sokoloev2019-06-16 20:58:01
Express.js
Sokoloev, 2019-06-16 20:58:01

How to create a global User variable in Express.js that is available on all pages?

Hello, I am creating, for educational purposes, the registration and authorization process, on Next.js, React, Express. There was a task to display the user login on all pages of the site, I know that using a preprocessor, for example, EJS, you can write in the app.js file like this

res.render('index', {
    user: {
      id,
      login
    }
  });
});

and then in the template just refer to the variable. But how to do it without EJS, so that you can then refer to the user just as easily, in any react component, on any page of the site?
<%= user.login %>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question