Florian Bouillon d76f412b82 feat: Add moer element
Signed-off-by: Florian BOUILLON <f.bouillon@aptatio.com>
2023-06-27 18:30:44 +02:00

21 lines
485 B
TypeScript

import { defineMiddleware } from "astro/middleware"
import { validateAuth } from '../libs/validateAuth'
// `context` and `next` are automatically typed
export default defineMiddleware(async (context, next) => {
if (!context.request.url.includes('api')) {
return next()
}
const auth = await validateAuth(context.request, {
name: 'slicing.slice',
api: true,
cookie: true
})
if (typeof auth === 'object') {
return auth
}
context.locals.authKey = auth
return next()
})