Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getToken({ req, token }) {
if (token) {
return token;
}
if (req) {
const cookie = require('cookie');
if (!req.headers || !req.headers.cookie) {
return;
}
const { token } = cookie.parse(req.headers.cookie);
return token;
} else {
const cookie = require('js-cookie');
return cookie.get('token');
}
}