-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating cookie setting, reformat usercontrollers, add jwt which is n…
…ot quite working
- Loading branch information
1 parent
cf5b54d
commit 912b11c
Showing
4 changed files
with
96 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
//server/cookieController.js | ||
const jwt = require('jsonwebtoken'); | ||
require("dotenv").config(); | ||
|
||
const cookieController = {}; | ||
|
||
/* | ||
* setSSIDCookie - store the user id in a cookie | ||
*/ | ||
cookieController.setSSIDCookie = (req, res, next) => { | ||
// console.log('res.locals.user is: ', res.locals.user); | ||
if (res.locals.user) { | ||
console.log('cookieController.setSSIDCookie res.locals.user._id.id: ', res.locals.user._id.id ) | ||
res.cookie('ssid', res.locals.user._id.id, {httpOnly: true}); | ||
return next(); | ||
} else { | ||
return next(); | ||
console.log('in set cookie, res.locals.userId is: ', res.locals.userId); | ||
if (!res.locals.userId){ | ||
return next({ | ||
log: 'Error in cookieController.setSSIDCookie - no user info.', | ||
message: {err: 'Error setting cookies, see server log for details.'} | ||
}) | ||
} | ||
// SERVER HANGS HERE - SOMETHING UP WITH JWT SIGNING BLOCK | ||
jwt.sign({ userId: res.locals.userId }, process.env.SECRET), (err, token) => {// promises not supported | ||
console.log(token) | ||
//try { | ||
if(err){ | ||
return next({ | ||
message: {err: 'Error in cookieController.setSSIDCookie.'}, | ||
log: `Problem creating token: ${err}` | ||
}) | ||
} | ||
res.cookie('ssid', token); | ||
return next() | ||
//} | ||
// catch (error) { | ||
// return next({ | ||
// message: {err: 'Error in cookieController.setSSIDCookie.'}, | ||
// log: `Problem setting cookies: ${err}` | ||
// }) | ||
// } | ||
} | ||
|
||
}; | ||
|
||
module.exports = cookieController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters