My NextJS application is a multi-tenant SaaS application where each customer can choose to use a subdomain on our site or map their custom domain via CNAME.
This setup allows customers to enable their employees to log in on either the subdomain site or custom domain.
Within the [...nextauth].js file, there is a signIn callback that executes after sign-in:
async signIn({ user, account, profile, email, credentials }) {
return true
},
In this callback, I need to determine which custom domain or subdomain the user is signing in from and apply specific logic accordingly. However, as the callback does not have access to req headers, how can I retrieve the domain/hostname within it? Depending on the domain, my goal is to permit/block signin or trigger other actions.