I checked this (commit history) but can't access the
originalImplementation
object. Is there an updated example?
r
rp_st
11/08/2022, 5:17 AM
hey @dhatguy can you be a bit more specific about what you are looking for here?
d
dhatguy
11/08/2022, 6:43 AM
I want the override functions in separate files
r
rp_st
11/08/2022, 6:45 AM
Not sure if I can help here. It’s just JS related question. If you have a question specific to supertokens, lmk 🙂
d
dhatguy
11/08/2022, 6:52 AM
Copy code
export 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 AM
how can I access
originalImplementation
?
r
rp_st
11/08/2022, 6:55 AM
You can do something like:
Copy code
export default getOverrideFunction(originalImplmenetation) {
return async function (input: {...}) {
// your implementation here
}
}
SuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).