How to create login API in node js?

I am developing a web application that is fully written in node js. All the functionality and the web interface are complete.

What happens, I can hit the services API without entering the application. This is similar to the fact that you can use services without entering the application.

Can someone tell me how can I create an API for logging in so that before the user logs in, he can not use the services?

Any help would be appreciated.

+4
source share
3 answers

passportjs, . , .

http://passportjs.org/

.

+4

, , , ( ).

- , ( express-session )

var isLoggedIn = function(req, res, next) {
  if (!req.session.username) {
    res.redirect('/login');
  }
  next();
}

API.

app.get('/home', isLoggedIn, function(req, res) {
  res.sendFile(path.join(__dirname+'/views/home.html'));
});
+1

, , , API nodeJS. , JS , . : https://github.com/themikenicholson/passport-jwt. RESTful .

0

Source: https://habr.com/ru/post/1679118/


All Articles