Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

safeAssertBearerToken

A safe version of assertBearerToken that handles errors and presents them as a property on the returned object instead.

Example

const handler = (req, res) => { const authorization = req.get('authorization'); const { error, data: token } = @neverstew.safeAssertBearerToken(@me.secrets.superSecret, authorization); if (error) { res.status(401).send("Unauthorized"); return; } res.json(token); }