I created a function like this:
const token = req.cookies['SESSION_DATA'] if (token) { ... } catch (err) { ... }
However, when I try to check for a token, I receive a TypeError stating "Cannot read property of undefined."
Interestingly, the same function works without any issues in another project where it doesn't throw an error even when there is no cookie named 'SESSION_DATA'. I attempted to set const token = undefined
, but it never passed the if statement. When I attempt to verify the existence of cookies using req.cookies['SESSION_DATA']
, I still encounter a TypeError, even though it's within an if statement.