mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-09 20:12:10 +10:00
Combined fixes (#116)
* fix: missing CheckIcon import in LanguageSelector * fix: #114 and error handling * fix: #97 * fix: lint * feat: #104 * fix: #72
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
import { H3Error } from "h3";
|
||||
import sessionHandler from "../internal/session";
|
||||
|
||||
export default defineNitroPlugin((nitro) => {
|
||||
nitro.hooks.hook("error", async (error, { event }) => {
|
||||
if (!event) return;
|
||||
|
||||
// Don't handle for API routes
|
||||
if (event.path.startsWith("/api")) return;
|
||||
if (event.path.startsWith("/auth")) return;
|
||||
|
||||
// Make sure it's a web error
|
||||
if (!(error instanceof H3Error)) return;
|
||||
|
||||
switch (error.statusCode) {
|
||||
case 401:
|
||||
case 403: {
|
||||
const user = await sessionHandler.getSession(event);
|
||||
if (user) break;
|
||||
return sendRedirect(
|
||||
event,
|
||||
`/auth/signin?redirect=${encodeURIComponent(event.path)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user