link-stack/apps/link/middleware.ts

31 lines
662 B
TypeScript
Raw Normal View History

2023-05-24 20:27:57 +00:00
import { withAuth } from "next-auth/middleware";
export default withAuth(
() => { },
{
pages: {
signIn: `/login`,
},
callbacks: {
authorized: ({ token, req }) => {
const {
url,
headers,
} = req;
// 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";
return false;
},
}
}
);