diff --git a/server/controllers/api/apiIndex.js b/server/controllers/api/apiIndex.js index 87a267c..3805788 100644 --- a/server/controllers/api/apiIndex.js +++ b/server/controllers/api/apiIndex.js @@ -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); } } diff --git a/server/controllers/auth.js b/server/controllers/auth.js index e03c4b0..5f65c2e 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -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) { diff --git a/server/middleware/userValidator.js b/server/middleware/userValidator.js index f88be78..b0d9084 100644 --- a/server/middleware/userValidator.js +++ b/server/middleware/userValidator.js @@ -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, }) diff --git a/server/server.js b/server/server.js index 41c3dea..87e4704 100644 --- a/server/server.js +++ b/server/server.js @@ -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)); diff --git a/server/services/signToken.js b/server/services/signToken.js index a6cebb8..f7260a3 100644 --- a/server/services/signToken.js +++ b/server/services/signToken.js @@ -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; \ No newline at end of file diff --git a/server/socket.js b/server/socket.js index 8d47c2f..4708e7d 100644 --- a/server/socket.js +++ b/server/socket.js @@ -2,7 +2,6 @@ module.exports = { enableSocket: io => { - // io.on('connection', () => console.log('connected')) io.on('connection', ()=> { io.emit('connected', {message: 'socket connected'}); })