Open aleclarson opened 2 years ago
This can be implemented with an onRequest
hook once it supports a route argument.
import { onRequest } from 'saus'
onRequest('/admin/*', async req => {
return (await verifyAdmin(req))
? undefined
: [307, { Location: '/login' }]
})
We could add a notAuthorized
helper function:
import { onRequest, notAuthorized } from 'saus'
onRequest('/admin/*', async req => {
return (await verifyAdmin(req))
? undefined
: notAuthorized(req, '/login')
})
It would respond with 307 temporary redirect if Accept: text/html
header exists.
Otherwise, it would respond with 403 forbidden.
⚠️ The example in this OP is outdated. See https://github.com/alloc/saus/issues/56#issuecomment-1143963756
Add an
authorizeRoutes
route hook, used like so: