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.
27 lines
621 B
27 lines
621 B
import { UNAUTHORIZED_MESSAGE } from "#server/constants/auth";
|
|
import { isAllowlistedApiPath } from "#server/utils/auth-api-routes";
|
|
import { getCurrentUser } from "#server/utils/context";
|
|
|
|
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 getCurrentUser(event);
|
|
if (user) {
|
|
return;
|
|
}
|
|
|
|
throw createError({
|
|
statusCode: 401,
|
|
statusMessage: UNAUTHORIZED_MESSAGE,
|
|
});
|
|
});
|
|
|