38 lines
904 B
TypeScript
38 lines
904 B
TypeScript
import { withAuth } from "next-auth/middleware";
|
|
|
|
export default withAuth(
|
|
{
|
|
pages: {
|
|
signIn: `/login`,
|
|
},
|
|
callbacks: {
|
|
authorized: ({ token, req }) => {
|
|
const {
|
|
url,
|
|
} = req;
|
|
const parsedURL = new URL(url);
|
|
|
|
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) {
|
|
return true;
|
|
}
|
|
|
|
if (token?.email) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
}
|
|
}
|
|
);
|
|
|
|
export const config = {
|
|
matcher: [
|
|
'/((?!api|app|bootstrap|3961|ui|translations|internal|login|node_modules|_next/static|_next/image|favicon.ico).*)',
|
|
],
|
|
};
|