dhatguy
11/07/2022, 8:37 PMoriginalImplementation
object. Is there an updated example?rp_st
11/08/2022, 5:17 AMdhatguy
11/08/2022, 6:43 AMrp_st
11/08/2022, 6:45 AMdhatguy
11/08/2022, 6:52 AMexport default async function (input: {
token: string;
options: APIOptions;
userContext: any;
session?: Session.SessionContainer | undefined;
}) {
try {
console.log(Number(input.token));
if (originalImplementation.verifyEmailPOST === undefined) {
throw Error("🚩Should never come here🚩");
}
const result = await pool.query(
"SELECT * FROM one_time_pin WHERE otp = $1",
[input.token]
);
if (result.rows.length === 0) {
throw new HttpException(400, "Invalid OTP");
}
// First we call the original implementation
const response = await originalImplementation.verifyEmailPOST({
...input,
token: result.rows[0].token,
});
// Then we check if it was successfully completed
if (response.status === "OK") {
// Then we delete the otp from the database
await pool.query("DELETE FROM one_time_pin WHERE otp = $1", [
input.token,
]);
}
return response;
} catch (error: any) {
throw new HttpException(error.statusCode, error.message);
}
}
dhatguy
11/08/2022, 6:52 AMoriginalImplementation
?rp_st
11/08/2022, 6:55 AMexport default getOverrideFunction(originalImplmenetation) {
return async function (input: {...}) {
// your implementation here
}
}
And then in the supertokens.init place, you call getOverrideFunction(originalImplementation)
dhatguy
11/08/2022, 6:56 AM