link-stack/apps/leafcutter/middleware.ts

39 lines
904 B
TypeScript
Raw Normal View History

2023-08-25 07:11:33 +00:00
import { withAuth } from "next-auth/middleware";
2023-06-28 09:09:45 +00:00
2023-05-25 12:37:14 +00:00
export default withAuth(
{
pages: {
signIn: `/login`,
},
callbacks: {
authorized: ({ token, req }) => {
const {
url,
} = req;
2023-06-28 09:09:45 +00:00
const parsedURL = new URL(url);
2023-08-25 07:11:33 +00:00
console.log({ url });
console.log({ pathname: parsedURL.pathname });
console.log({ allowed: parsedURL.pathname.startsWith("/app") });
const allowed = parsedURL.pathname.startsWith('/login') || parsedURL.pathname.startsWith('/api' || parsedURL.pathname.startsWith("/app"));
if (allowed) {
2023-06-28 09:09:45 +00:00
return true;
}
2023-08-25 07:11:33 +00:00
if (token?.email) {
2023-06-28 09:09:45 +00:00
return true;
}
return false;
2023-08-25 07:11:33 +00:00
2023-05-25 12:37:14 +00:00
},
}
}
);
2023-08-25 07:11:33 +00:00
export const config = {
matcher: [
'/((?!api|app|bootstrap|3961|ui|translations|internal|login|node_modules|_next/static|_next/image|favicon.ico).*)',
],
};