link-stack/apps/leafcutter/middleware.ts
2023-05-26 08:06:16 +00:00

46 lines
1.1 KiB
TypeScript

import { withAuth } from "next-auth/middleware";
import getConfig from "next/config";
export default withAuth(
() => { },
{
pages: {
signIn: `/login`,
},
callbacks: {
authorized: ({ token, req }) => {
const {
url,
headers,
} = req;
return true;
/*
const {
publicRuntimeConfig: { embedded },
} = getConfig();
if (embedded) {
return true;
}
// check login page
const parsedURL = new URL(url);
if (parsedURL.pathname.startsWith('/login')) {
return true;
}
// check session auth
const authorizedDomains = ["redaranj.com", "digiresilience.org"];
const userDomain = token?.email?.toLowerCase().split("@").pop() ?? "unauthorized.net";
if (authorizedDomains.includes(userDomain)) {
return true;
}
return false;
*/
},
}
}
);