Answer the question
In order to leave comments, you need to log in
Which node.js module running on the client to use for localStorage?
Good day to all. What module would you recommend to use to install localStorage?
The bottom line is that I need to configure the authorization to the end, with successful authorization it is necessary that "hello user" is displayed instead of the signin and signup buttons, at the moment my architecture is such that these buttons are in the header block (menu) connected to all pages. It is connected to all pages and is not located in the same directory as them.
.../views/index.ejs
.../views/signin.ejs
.../views/blocks/header.ejs
here is the
architecture
router.post('/signin', (req, res, next) => {
passport.authenticate('signin', (authenticateError, user, info) => {
if (authenticateError) {
next(authenticateError);
return;
}
if (info && info.message) {
res.render('signin', {
errorMessage: info.message
});
return;
}
req.logIn(user, (err) => {
if (err) {
next(err);
return;
}
console.log("===================" + user.email); <----тут для теста при верной авторизе вывожу мыло юзера
res.redirect('/'); <------- тут он редиректит на главную
});
})(req, res, next);
});
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.1">
<link rel="stylesheet" href="./public/css/signin.css" type="text/css"/>
</head>
<header>
<% include blocks/header.ejs %>
</header>
<div id="log-acc">
<div id="wr">
<p id="description">Login</p>
<p id="warning">Enter your email and password</p>
<form action="/signin" method="post">
<div>
<input type="email" name="email" id="email" class="data" placeholder="EMAIL" required>
</div>
<div>
<input type="password" name="password" id="password" class="data" placeholder="PASSWORD" required>
</div>
<div>
<button id="form-auth">Login Now</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Firstly, if you use a passport for authorization, then do it according to the documentation. There is no need to reinvent the wheel, everything has already been done for you:
router.post('/signin', passport.authenticate('signin',
{
successRedirect: '/',
failureRedirect: '/login'
}
));
res.render('signin', {
errorMessage: info.message,
user: req.user
});
if user
button(type="submit") signin
button(type="submit") signup
else
h1 Hello #{user.name}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question