mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use jsonwebtoken verify instead of decode for older version of the lib
This commit is contained in:
parent
c0872939a7
commit
dda57860cb
1 changed files with 13 additions and 3 deletions
|
|
@ -228,14 +228,24 @@ export const findThumbnail = async (
|
|||
|
||||
export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
|
||||
async (req, res) => {
|
||||
if (!process.env.JWT_SECRET) {
|
||||
console.error('JWT_SECRET not exists')
|
||||
return res.status(500).send('JWT_SECRET_NOT_EXISTS')
|
||||
}
|
||||
|
||||
const token = req.headers?.authorization
|
||||
if (!token) {
|
||||
console.debug('no token')
|
||||
return res.status(401).send('UNAUTHORIZED')
|
||||
}
|
||||
const { uid } = jwt.decode(token) as { uid: string }
|
||||
if (!uid) {
|
||||
console.debug('no uid')
|
||||
let uid = ''
|
||||
try {
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET) as {
|
||||
uid: string
|
||||
}
|
||||
uid = decoded.uid
|
||||
} catch (e) {
|
||||
console.debug('invalid token')
|
||||
return res.status(401).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue