Spaces:
Paused
Paused
File size: 600 Bytes
c8cfaf5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import { checkAuthentication, isAuthRequired } from '../../utils/auth.js';
import { apiError } from '../../utils/api-v1.js';
export async function onRequest(context) {
if (!context.env?.img_url) {
return apiError(
'SERVER_MISCONFIGURED',
'KV binding img_url is not configured.',
500
);
}
if (!isAuthRequired(context.env)) {
return context.next();
}
const authResult = await checkAuthentication(context);
if (authResult.authenticated) {
return context.next();
}
return apiError('UNAUTHORIZED', 'You need to login.', 401);
}
|