-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
51 lines (33 loc) · 1.42 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require ('express');
const router = express.Router();
//const bcrypt = require ('bcrypt');
//const pg = require ('./db/conn');
//to validate all user data
function validUser(user){
const validEmail = typeof user.email == 'String'
&& user.email.trim() != '';
const validPassword = typeof user.password == 'String' && user.password.trim() != ''
&& user.password.trim().lenght >= 8;
//const validFirst_name = typeof user.first_name == 'String' && user.first_name.trim() != '';
//const validlast_name = typeof user.last_name == 'String' && user.last_name.trim() != '';
return validEmail && validPassword ;//&& validFirst_name && validlast_name ;
}
//user signup
router.post('/v1/signup',(req, res, next) => {
const results = [];
//grab data from input request
//const data = {email:req.body.email, password:req.body.password, first_name:req.body.first_name, last_name:req.body.last_name};
//connect to database
const pg = require('pg');
const connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/wayfarer_db';
const client = new pg.Client(connectionString, (err,client,done) => {
//handling connection errors
if(err){
done();
console.log(err);
return res.status(500).json({success: false, data: err});
}
});
client.connect()
});
module.exports = router;