refactor auth and api/index to ensure token verified and sent to dispatch ADD_USER
This commit is contained in:
parent
465a3342f2
commit
b8b7890e4f
6 changed files with 12 additions and 10 deletions
|
@ -5,13 +5,13 @@ const apiIndex = async (req, res, next) => {
|
|||
try {
|
||||
if (req.cookies && req.cookies.token) {
|
||||
const token = req.cookies.token;
|
||||
const verifiedToken = verifyToken(token);
|
||||
res.status(200).json(verifiedToken.user)
|
||||
const verifiedToken = await verifyToken(token);
|
||||
res.status(200).send(verifiedToken.user)
|
||||
}
|
||||
res.status(200).json()
|
||||
}
|
||||
|
||||
catch {
|
||||
catch (err) {
|
||||
res.status(500).json(err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ const signup = async (req, res, next) => {
|
|||
}
|
||||
|
||||
const newUser = await userQueries.insertUser(secureUser)
|
||||
signToken(res, newUser).status(201).json({...newUser});
|
||||
signToken(res, newUser)
|
||||
res.status(201).json({...newUser});
|
||||
}
|
||||
|
||||
catch (err) {
|
||||
|
|
|
@ -25,7 +25,6 @@ const validate = (req, res, next) => {
|
|||
}
|
||||
const extractedErrors = []
|
||||
errors.array().map(err => extractedErrors.push({ [err.param]: err.msg }))
|
||||
|
||||
return res.status(422).json({
|
||||
errors: extractedErrors,
|
||||
})
|
||||
|
|
|
@ -19,9 +19,10 @@ const apiRouter = require('./routes/api');
|
|||
|
||||
const app = express();
|
||||
|
||||
const allowedOrigin = process.env.NODE_ENV === 'production' ? process.env.REACT_ADDRESS : '*';
|
||||
const allowedOrigin = process.env.REACT_ADDRESS;
|
||||
const corsOptions = {
|
||||
origin: allowedOrigin
|
||||
origin: allowedOrigin,
|
||||
credentials: true
|
||||
}
|
||||
|
||||
app.options('*', cors(corsOptions));
|
||||
|
|
|
@ -12,8 +12,10 @@ const signToken = (res, user) => {
|
|||
});
|
||||
return res.cookie('token', token, {
|
||||
expires: new Date(Date.now() + expiration),
|
||||
secure: false, // set to true if your using https
|
||||
httpOnly: true,
|
||||
domain: process.env.DOMAIN,
|
||||
// secure: false, // set to true if your using https
|
||||
httpOnly: true
|
||||
// path: '/api/v1'
|
||||
});
|
||||
};
|
||||
module.exports = signToken;
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
module.exports = {
|
||||
enableSocket: io => {
|
||||
// io.on('connection', () => console.log('connected'))
|
||||
io.on('connection', ()=> {
|
||||
io.emit('connected', {message: 'socket connected'});
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue