I checked this (commit history) but can't access t...
# general
d
I checked this (commit history) but can't access the
originalImplementation
object. Is there an updated example?
r
hey @dhatguy can you be a bit more specific about what you are looking for here?
d
I want the override functions in separate files
r
Not sure if I can help here. It’s just JS related question. If you have a question specific to supertokens, lmk 🙂
d
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);
  }
}
how can I access
originalImplementation
?
r
You can do something like:
Copy code
export default getOverrideFunction(originalImplmenetation) {
   return async function (input: {...}) {
      // your implementation here
   }
}
And then in the supertokens.init place, you call
getOverrideFunction(originalImplementation)
d
alright, thanks
2 Views