As in the title, when I request a logout, I have tried logic in various ways to respond to the 205 status code, but I can not write the appropriate logic.
If the user ID or password received at the login request is perfectly consistent with the information stored in the database, the 'ok' message and status code 200 must be included in the response. ✓
If the user ID or password received at the login request is i- nvalid, the 'invalid user' message and status code 404 must be included in the response. ✓
If you succeed in logining, you must forward JWT tokens to cookies. ✓
// server/controllers/users/signout.js
module.exports = (req, res) => {
//TODO: ## Create logout logic ##
res.status(500).send();
};
// server/controllers/users/signin.js
[ This is what I wrote about the signin logic ]
const { request } = require('express');
const { user } = require('../../models');
const { generateAccessToken, sendAccessToken } = require('../tokenFunctions');
module.exports = async (req, res) => {
//TODO: Deliver tokens after user authentication through login information
await user
.findOne({
where: { email: req.body.email, password: req.body.password },
})
.then((userObject) => {
if (userObject) {
res.append('set-cookie', 'jwt');
res.status(200).json({ message: 'ok' });
} else {
res.status(404).send('invalid user');
}
});
};
// server/tokenFuntions/index.js
require('dotenv').config();
const { sign, verify } = require('jsonwebtoken');
module.exports = {
generateAccessToken: (data) => {
//TODO: sign with token
},
sendAccessToken: (res, accessToken) => {
//TODO: Deliver JWT tokens to cookies.
res.json({ message: 'ok' });
},
isAuthorized: (req) => {
//TODO: Verify by receiving JWT token information.
//HINT: Receive JWT token information and verify it.Return the decoded payload using the verify function of the Jsonwebtoken library.
},
};
// server/controllers/users/index.js
module.exports = {
auth: require('./users/auth'),
signup: require('./users/signup'),
signin: require('./users/signin'),
signout: require('./users/signout'),
};