diff --git a/packages/play-node-go/play-node-go/src/App.js b/packages/play-node-go/play-node-go/src/App.js index 108cc1e..d960d6c 100644 --- a/packages/play-node-go/play-node-go/src/App.js +++ b/packages/play-node-go/play-node-go/src/App.js @@ -14,6 +14,7 @@ import Room from './pages/Room/Room'; export const socket = socketIOClient(config.apiAddress); + function App() { const [fetchData, setFetchData] = useState(); const [socketData, setSocketData] = useState(); @@ -32,7 +33,6 @@ function App() { socket.on('connect_error', err => setError([...error, err])); socket.on('error', err => setError([...error, err])) }) - return ( diff --git a/packages/play-node-go/play-node-go/src/services/authServices.js b/packages/play-node-go/play-node-go/src/services/authServices.js index 916d733..19abf05 100644 --- a/packages/play-node-go/play-node-go/src/services/authServices.js +++ b/packages/play-node-go/play-node-go/src/services/authServices.js @@ -10,18 +10,17 @@ const loginService = () => { } const signupService = async (formData) => { - const response = await Axios.post(signupEndpoint, { - ...formData - }).then(res => { + const response = await Axios.post(signupEndpoint, {...formData }) + .then(res => { return res; }).catch(err => { + console.log(err) return err; }); - console.log(response) return response; } -module.exports = { +export default { loginService, signupService } \ No newline at end of file diff --git a/packages/play-node-go/play-node-go/src/services/authServices.test.js b/packages/play-node-go/play-node-go/src/services/authServices.test.js index 396168c..9e61ab9 100644 --- a/packages/play-node-go/play-node-go/src/services/authServices.test.js +++ b/packages/play-node-go/play-node-go/src/services/authServices.test.js @@ -6,15 +6,12 @@ const loginService = authServices.loginService; const newUserFormData = { username:'newUser', password:'password', - passwordConfirm:'password', + confirmPassword:'password', email:'user@example.com' } describe('signupService', () => { - it('signup returns 200', async () => { - const response = await signupService(newUserFormData); - console.log(response) - expect(response.status).equal('200'); + it('', () => { }); }); diff --git a/packages/play-node-go/server/controllers/auth.js b/packages/play-node-go/server/controllers/auth.js index eeee50c..ca248dd 100644 --- a/packages/play-node-go/server/controllers/auth.js +++ b/packages/play-node-go/server/controllers/auth.js @@ -13,27 +13,24 @@ const checkValidationErrors = (req, res) => { } const signup = async (req, res, next) => { - checkValidationErrors(req, res); const user = req.body; - try { - + delete user.confirmPassword; const hashedPassword = await hashPassword(user.password); const secureUser = { ...user, password: hashedPassword } - + knex('user') .returning(['username', 'email']) .insert(secureUser) .then(queryResults => { const newUser = queryResults[0]; - signToken(res, newUser); - res.send('ok').status(200); + signToken(res, newUser).send('ok').status(201); }) } catch (err) { - res.status(500).json(err) + res.status(500).json(err); } } diff --git a/packages/play-node-go/server/middleware/userValidator.js b/packages/play-node-go/server/middleware/userValidator.js index d816404..f88be78 100644 --- a/packages/play-node-go/server/middleware/userValidator.js +++ b/packages/play-node-go/server/middleware/userValidator.js @@ -5,6 +5,8 @@ const signupValidationRules = () => { check('email', 'invalid email').normalizeEmail().isEmail(), check('username', 'invalid username').isString(), check('password', 'invalid password').isString().isLength({min: 8}), + check('confirmPassword', 'invalid password').isString() + .custom((confirmPassword, { req }) => confirmPassword === req.body.password), sanitize('username').escape() ] } @@ -17,7 +19,7 @@ const loginValidationRules = () => { } const validate = (req, res, next) => { - const errors = validationResult(req) + const errors = validationResult(req); if (errors.isEmpty()) { return next() } diff --git a/packages/play-node-go/server/server.js b/packages/play-node-go/server/server.js index b469e0c..6b81972 100644 --- a/packages/play-node-go/server/server.js +++ b/packages/play-node-go/server/server.js @@ -19,8 +19,9 @@ const apiRouter = require('./routes/api'); const app = express(); +const allowedOrigin = process.env.NODE_ENV === 'production' ? env.REACT_ADDRESS : '*'; const corsOptions = { - origin: process.env.REACT_ADDRESS + origin: allowedOrigin } app.options('*', cors(corsOptions)); diff --git a/packages/play-node-go/server/services/bcrypt.js b/packages/play-node-go/server/services/bcrypt.js index f59d05f..2dfbcec 100644 --- a/packages/play-node-go/server/services/bcrypt.js +++ b/packages/play-node-go/server/services/bcrypt.js @@ -1,12 +1,12 @@ const bcrypt = require('bcrypt'); require('dotenv').config(); -const saltRounds = process.env.NODE_ENV === 'test' ? 5 : process.env.SALT_ROUNDS; +const saltRounds = process.env.NODE_ENV === 'test' ? 5 : parseInt(process.env.SALT_ROUNDS); const hashPassword = async (password) => { - const hashedPassword = await new Promise((resolve, reject) => { bcrypt.hash(password, saltRounds, (err, hash) => { + console.log(err) if (err) reject(err) resolve(hash) }); diff --git a/packages/play-node-go/server/socket.js b/packages/play-node-go/server/socket.js index e3aeefb..8d47c2f 100644 --- a/packages/play-node-go/server/socket.js +++ b/packages/play-node-go/server/socket.js @@ -2,8 +2,8 @@ module.exports = { enableSocket: io => { - io.on('connection', () => console.log('connected')) - io.on('connect', ()=> { + // io.on('connection', () => console.log('connected')) + io.on('connection', ()=> { io.emit('connected', {message: 'socket connected'}); }) diff --git a/packages/play-node-go/server/test/auth.login.spec.js b/packages/play-node-go/server/test/auth.login.spec.js index 78ebcf8..5ec5ec7 100644 --- a/packages/play-node-go/server/test/auth.login.spec.js +++ b/packages/play-node-go/server/test/auth.login.spec.js @@ -2,6 +2,7 @@ const authSignupSpec = (chai, knex, server) => { const newUserFormData = { 'username':'newUser', 'password':'password', + 'confirmPassword':'password', 'email':'user@example.com' } const loginFormData = { diff --git a/packages/play-node-go/server/test/auth.signup.spec.js b/packages/play-node-go/server/test/auth.signup.spec.js index 218a98f..9af5496 100644 --- a/packages/play-node-go/server/test/auth.signup.spec.js +++ b/packages/play-node-go/server/test/auth.signup.spec.js @@ -4,21 +4,25 @@ const authSignupSpec = (chai, knex, server) => { const newUserFormData = { 'username':'newUser', 'password':'password', + 'confirmPassword':'password', 'email':'user@example.com' } const invalidEmailFormData = { 'username':'newUser', 'email': 'useremail', - 'password':'password' + 'password':'password', + 'confirmPassword':'password' } const scriptInjectionFormData = { 'username': '', 'password':'password', + 'confirmPassword':'password', 'email':'user@example.com' } const sqlInjectionFormData = { 'username': '; DROP TABLE user;', 'password':'password', + 'confirmPassword':'password', 'email':'user@example.com' }