Social Sign-in Invited Emails Only
Hi guys, i am working on a project where the signups are disabled and allowed only to the invited emails. for email password signups i have implemented it with hooks, but the issue coming is with social providers. i have listened to the context in after hooks. and throwing the error in case unauthorized with apierror and its fine but on server's endpoint and when i used ctx.redirect with throw or even return it doesnt work and let the user go through.
this is my hooks config for both email/password and social provider:
hooks: {
after: createAuthMiddleware(async (ctx) => {
console.log("Hook path:", ctx.path);
if (ctx.path === "/callback/:id" && ctx.request?.url.includes("callback/google")) {
const returned = ctx.context.returned as AuthHookResponse | undefined;
const email = ctx.context.newSession?.user.email || (returned && isSuccessResponse(returned) ? returned.user.email : null);
console.log("google email", email);
if (!email) {
console.log("No email found in Google callback");
return ctx.redirect("http://localhost:3000/login?error=no_email");
}
if (email !== "[email protected]") {
console.log("Unauthorized email:", email);
throw new APIError("UNAUTHORIZED", {
message: "iNVALID INVITE",
})
// throw ctx.redirect("http://localhost:3000/login?error=unauthorized");
}
}
}),
},
and the screenshot is attached for throwing an apierror

1 Reply
@admin