Skip to content

Commit 9778914

Browse files
committed
Fix: Deserialize user
1 parent b3cd29c commit 9778914

File tree

3 files changed

+49
-35
lines changed

3 files changed

+49
-35
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
},
4343
"devDependencies": {
4444
"redux-devtools-extension": "^2.13.2"
45-
}
45+
},
46+
"proxy": "http://localhost:3001"
4647
}

server/index.js

+44-32
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,40 @@ const projectsController = require('./controllers/projects_controller');
2525
const tasksController = require('./controllers/tasks_controller');
2626
const socket = require('./socketServer');
2727

28-
const app = express();
29-
app.use( express.static( `${__dirname}/../build` ) );
30-
app.use(bodyParser.json()); //Must come before cors
31-
// app.use(cors());
32-
app.use((req, res, next) => {
33-
res.header('Access-Control-Allow-Origin', '*');
34-
res.header('Access-Control-Allow-Methods', 'GET,POST,DELETE');
35-
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested With, Content-Type, Accept');
36-
res.header('Access-Control-Allow-Credentials', 'true');
37-
next();
38-
});
39-
app.use(passport.initialize());
40-
app.use(passport.session());
4128

4229

30+
const app = express();
4331
///////////////////////////////////////////////////////////////////////////
4432
// DATABASE
4533
massive(DB_CONN_STRING)
4634
.then(instance => {
4735
app.set('db', instance);
4836
})
4937
.catch(console.log);
50-
///////////////////////////////////////////////////////////////////////////
38+
// app.use( express.static( `${__dirname}/../build` ) );
39+
app.use(bodyParser.json()); //Must come before cors
40+
app.use(cors());
41+
// app.use((req, res, next) => {
42+
// res.header('Access-Control-Allow-Origin', '*');
43+
// res.header('Access-Control-Allow-Methods', 'GET,POST,DELETE');
44+
// res.header('Access-Control-Allow-Headers', 'Origin, X-Requested With, Content-Type, Accept');
45+
// res.header('Access-Control-Allow-Credentials', 'true');
46+
// next();
47+
// });
5148
app.use(
5249
session({
5350
secret: 'placeholder',
54-
resave: true,
55-
saveUninitialized: true,
56-
cookie: { maxAge: 600000 }
51+
resave: false,
52+
saveUninitialized: false,
53+
cookie: { maxAge: 600000, httpOnly:true }
5754
})
5855
);
59-
app.use(flash());
56+
app.use(passport.initialize());
57+
app.use(passport.session());
58+
59+
///////////////////////////////////////////////////////////////////////////
60+
61+
6062
///////////////////////////////////////////////////////////////////////////
6163
//PERSISTENCE
6264
passport.serializeUser(function(user, done) {
@@ -65,16 +67,18 @@ passport.serializeUser(function(user, done) {
6567
});
6668

6769
passport.deserializeUser(function(id, done) {
68-
db.users
69-
.findOne({ where: { id: id } })
70-
.then(user => {
71-
console.log(`DESERIALIZE USER: ${user[0].id} | ${user[0].username}`);
72-
if (user) {
73-
return done(null, user);
74-
}
75-
return done(null, false);
76-
})
77-
.catch(err => done(err));
70+
console.log(`DESERIALIZE USER: ${id}`);
71+
// db.users
72+
// .findOne({ where: { id: id } })
73+
// .then(user => {
74+
// console.log(`DESERIALIZE USER: ${user[0].id} | ${user[0].username}`);
75+
// if (user) {
76+
// return done(null, user);
77+
// }
78+
// return done(null, false);
79+
// })
80+
// .catch(err => done(err));
81+
return done(null, {user_id: id});
7882
});
7983
///////////////////////////////////////////////////////////////////////////
8084
// Passport strategies
@@ -280,7 +284,15 @@ app.delete('/api/deleteAllTasks/:cardID', tasksController.deleteAllTasks)
280284
app.delete('/api/deleteCard/:cardID', tasksController.deleteCard)
281285

282286

283-
287+
app.get('/api/user', (req, res) => {
288+
console.log('USER IN USER: ', req.user);
289+
console.log('SESSION ID IN USER: ', req.sessionID);
290+
if (req.user) {
291+
res.json(req.user);
292+
} else {
293+
res.json('failure')
294+
}
295+
})
284296

285297
///////////////////////////////////////////////////////////////////////////
286298
// More End Points
@@ -290,6 +302,6 @@ const server = app.listen(PORT, () => {
290302
});
291303

292304
const io = socket(server);
293-
app.get('*', (req, res)=>{
294-
res.sendFile(path.join(__dirname, '../build/index.html'));
295-
})
305+
// app.get('*', (req, res)=>{
306+
// res.sendFile(path.join(__dirname, '../build/index.html'));
307+
// })

src/components/Dashboard/Dashboard.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Dashboard extends Component {
2222
this.sendNewProject = this.sendNewProject.bind(this);
2323
}
2424
componentDidMount() {
25-
this.props.getAllProjects(this.props.userID);
26-
this.props.getAllTasks(this.props.userID);
25+
// this.props.getAllProjects(this.props.userID);
26+
// this.props.getAllTasks(this.props.userID);
27+
axios.get('/api/user/').then(response => console.log(response))
2728
}
2829

2930
// changes local state to allow tooltip to popup on create new project

0 commit comments

Comments
 (0)