Para su middleware para obtener el token (función de autenticación)
const { authorization } = req.headers
if (!authorization) {
console.log('[No Authorization Code]');
return res.status(401).send({ message: 'Unauthorized' });
}
if (!authorization.startsWith('Bearer')) {
console.log('[Authorization need to start with Bearer]')
return res.status(401).send({ message: 'Unauthorized' });
}
const split = authorization.split('Bearer ')
if (split.length !== 2) {
console.log('[Invalid Authorization Param')
return res.status(401).send({ message: 'Unauthorized' });
}
const token = split[1] //this is your token to use with jwt.verify
Cuando envíe el token al cartero, seleccione Bearer Token
Cuando comience a crear su interfaz, los códigos deben ser equivalentes a la siguiente solicitud de búsqueda
fetch('/api/path', { method: 'GET', headers: { "Authorization": `Bearer ${token}`}}).(res => res.json())
Puede cambiar el método a su método deseado (por ejemplo, obtener o publicar), y el token será el token jwt