You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
566 B
26 lines
566 B
import { UNAUTHORIZED_MESSAGE } from "#server/constants/auth";
|
|
import { isAllowlistedApiPath } from "#server/utils/auth-api-routes";
|
|
|
|
export default eventHandler(async (event) => {
|
|
const path = event.path;
|
|
if (!path.startsWith("/api/")) {
|
|
return;
|
|
}
|
|
if (path.startsWith("/api/_nuxt_icon")) {
|
|
return;
|
|
}
|
|
|
|
if (isAllowlistedApiPath(path, event.method)) {
|
|
return;
|
|
}
|
|
|
|
const user = await event.context.auth.getCurrent();
|
|
if (user) {
|
|
return;
|
|
}
|
|
|
|
throw createError({
|
|
statusCode: 401,
|
|
statusMessage: UNAUTHORIZED_MESSAGE,
|
|
});
|
|
});
|
|
|