Return data in my plugin

Hello, I would like my plugin to add additional information about the email to the request data, including types, and for it to be accessible on the server side from the request, but I don't know how to do it. Does anyone know?
export const dymoEmailPlugin = ({ apiKey, emailRules }: DymoEmailPluginOptions) => {
const defaultRules: EmailValidatorRules = {
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"] as NegativeEmailRules[]
};

const dymoClient = new DymoAPI({
apiKey,
rules: {
email: {
deny: emailRules?.deny ?? defaultRules.deny
}
}
});

return {
id: "dymoEmailPlugin",
hooks: {
before: [
{
matcher: (context: any) => context.path.startsWith("/sign-up/email"),
handler: createAuthMiddleware(async (ctx: any) => {
const { email } = ctx.body;

if (typeof email !== "string") throw new APIError("BAD_REQUEST", { message: "Email must be a string." });

const decision = await dymoClient.isValidEmail(email);

if (!decision.allow) {
throw new APIError("BAD_REQUEST", {
message: "Email is invalid or blocked.",
reasons: decision.reasons
});
}

ctx.dymoEmail = decision.response as DataEmailValidationAnalysis;

return { context: ctx };
})
}
]
}
} satisfies BetterAuthPlugin;
};
export const dymoEmailPlugin = ({ apiKey, emailRules }: DymoEmailPluginOptions) => {
const defaultRules: EmailValidatorRules = {
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"] as NegativeEmailRules[]
};

const dymoClient = new DymoAPI({
apiKey,
rules: {
email: {
deny: emailRules?.deny ?? defaultRules.deny
}
}
});

return {
id: "dymoEmailPlugin",
hooks: {
before: [
{
matcher: (context: any) => context.path.startsWith("/sign-up/email"),
handler: createAuthMiddleware(async (ctx: any) => {
const { email } = ctx.body;

if (typeof email !== "string") throw new APIError("BAD_REQUEST", { message: "Email must be a string." });

const decision = await dymoClient.isValidEmail(email);

if (!decision.allow) {
throw new APIError("BAD_REQUEST", {
message: "Email is invalid or blocked.",
reasons: decision.reasons
});
}

ctx.dymoEmail = decision.response as DataEmailValidationAnalysis;

return { context: ctx };
})
}
]
}
} satisfies BetterAuthPlugin;
};
7 Replies
TPEO x Little
TPEO x LittleOP•3w ago
Could someone please help me? Also, if you reply, please ping me so Discord will notify me
FalconiZzare
FalconiZzare•3w ago
@Max
TPEO x Little
TPEO x LittleOP•3w ago
Thank you for letting him know if anyone can help me 🙂 @Max Would you know how I can do that? I have researched the different plugins and documentation, but I don't quite see how to make it available to the developer when a user registers or logs in
Ping
Ping•3w ago
I don't think it's possible right now, using purely plugin logic
TPEO x Little
TPEO x LittleOP•3w ago
So I can't return additional information to the developer when I log in/register a user?
Ping
Ping•3w ago
no I just mean for what you want to do with the types
TPEO x Little
TPEO x LittleOP•3w ago
What exactly do you mean?

Did you find this page helpful?