hooks: {
before: createAuthMiddleware(async (ctx) => {
if (ctx.path.startsWith("/callback") && ctx.params?.id === "google") {
const hd = ctx.query?.hd;
if (!hd || (hd !== "domain1.com" && hd !== "domain2.com")) {
throw new APIError("BAD_REQUEST", {
message: "Google account must be from allowed domain",
});
}
return;
}
if (ctx.path !== "/sign-up/email") {
return;
}
const email = ctx.body?.email;
if (!email || (!email.endsWith("@domain1.com") && !email.endsWith("@domain2.com"))) {
throw new APIError("BAD_REQUEST", {
message: "Email domain is not allowed",
});
}
}),
},
hooks: {
before: createAuthMiddleware(async (ctx) => {
if (ctx.path.startsWith("/callback") && ctx.params?.id === "google") {
const hd = ctx.query?.hd;
if (!hd || (hd !== "domain1.com" && hd !== "domain2.com")) {
throw new APIError("BAD_REQUEST", {
message: "Google account must be from allowed domain",
});
}
return;
}
if (ctx.path !== "/sign-up/email") {
return;
}
const email = ctx.body?.email;
if (!email || (!email.endsWith("@domain1.com") && !email.endsWith("@domain2.com"))) {
throw new APIError("BAD_REQUEST", {
message: "Email domain is not allowed",
});
}
}),
},