-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1f19f2
commit b6a6f42
Showing
4 changed files
with
161 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use strict"; | ||
|
||
const jwt = require("jsonwebtoken"); | ||
|
||
// Promise wrapper for jwt.verify(). | ||
const jwtVerify = (token, secret) => { | ||
return new Promise((resolve, reject) => { | ||
|
||
jwt.verify(token, secret, (err, decoded) => { | ||
if (err === null) { | ||
return resolve(decoded); | ||
} | ||
|
||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
const checkSessionCookie = (req, res) => { | ||
if (req.cookies === undefined || req.cookies.session === undefined) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
const addSessionCookie = (req, res, token) => { | ||
res.cookie("session", token); | ||
} | ||
|
||
const remSessionCookie = (req, res) => { | ||
if (checkSessionCookie(...arguments) === true) { | ||
res.clearCookie("session"); | ||
req.cookies.session = undefined; | ||
} | ||
} | ||
|
||
const checkSession = (req, res) => { | ||
if (req.session === undefined || req.session.complete === false) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
const checkUser = (req, res) => { | ||
if (req.user === undefined) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
module.exports = { | ||
|
||
jwtVerify, | ||
|
||
checkSessionCookie, | ||
addSessionCookie, | ||
remSessionCookie, | ||
checkSession, | ||
checkUser | ||
}; |
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