code fix
CI/CD Pipeline / Build and Push PocketBase Docker Image (push) Successful in 13s
CI/CD Pipeline / i18n Catalog Check (push) Successful in 42s
CI/CD Pipeline / Build and Push App Docker Image (push) Successful in 2m8s
CI/CD Pipeline / Deploy to Kubernetes (push) Successful in 8m28s
CI/CD Pipeline / Build and Push PocketBase Docker Image (push) Successful in 13s
CI/CD Pipeline / i18n Catalog Check (push) Successful in 42s
CI/CD Pipeline / Build and Push App Docker Image (push) Successful in 2m8s
CI/CD Pipeline / Deploy to Kubernetes (push) Successful in 8m28s
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
import { describe, it, expect, vi } from "vitest";
|
||||||
|
import OverrideableBuilder from "supertokens-js-override";
|
||||||
|
import { withPasswordlessTelemetry } from "./auth-events.server";
|
||||||
|
|
||||||
|
vi.mock("@/lib/pocketbase/client", () => ({
|
||||||
|
pbAdmin: {
|
||||||
|
authPromise: Promise.resolve(),
|
||||||
|
getPlayerByAuthId: async () => undefined,
|
||||||
|
createActivity: async () => undefined,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const makeOriginalImpl = () => ({
|
||||||
|
createCode: async (input: any) => ({ status: "OK", input }),
|
||||||
|
consumeCode: async (input: any) => ({ status: "OK", user: { id: "u1" }, input }),
|
||||||
|
listCodes: async () => [],
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("withPasswordlessTelemetry", () => {
|
||||||
|
it("composes with an inner override that spreads the proxy (twilio recipe shape)", async () => {
|
||||||
|
const inner = (originalImplementation: any) => ({
|
||||||
|
...originalImplementation,
|
||||||
|
consumeCode: async (input: any) => originalImplementation.consumeCode(input),
|
||||||
|
});
|
||||||
|
|
||||||
|
const builder = new OverrideableBuilder(makeOriginalImpl() as any);
|
||||||
|
builder.override(withPasswordlessTelemetry(inner) as any);
|
||||||
|
const impl = builder.build() as any;
|
||||||
|
|
||||||
|
await expect(impl.createCode({ phoneNumber: "+15555550100" })).resolves.toMatchObject({
|
||||||
|
status: "OK",
|
||||||
|
});
|
||||||
|
await expect(impl.consumeCode({ preAuthSessionId: "x" })).resolves.toMatchObject({
|
||||||
|
status: "OK",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("works without an inner override", async () => {
|
||||||
|
const builder = new OverrideableBuilder(makeOriginalImpl() as any);
|
||||||
|
builder.override(withPasswordlessTelemetry() as any);
|
||||||
|
const impl = builder.build() as any;
|
||||||
|
|
||||||
|
await expect(impl.createCode({ phoneNumber: "+15555550100" })).resolves.toMatchObject({
|
||||||
|
status: "OK",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -60,11 +60,14 @@ export const withPasswordlessTelemetry =
|
|||||||
(originalImplementation: any) => {
|
(originalImplementation: any) => {
|
||||||
const base = existing ? existing(originalImplementation) : originalImplementation;
|
const base = existing ? existing(originalImplementation) : originalImplementation;
|
||||||
|
|
||||||
|
const callBase = (name: string, input: any) =>
|
||||||
|
(base[name] ?? originalImplementation[name]).call(originalImplementation, input);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
createCode: async (input: any) => {
|
createCode: async (input: any) => {
|
||||||
try {
|
try {
|
||||||
const response = await base.createCode(input);
|
const response = await callBase("createCode", input);
|
||||||
recordAuthEvent("auth.otp_sent", {
|
recordAuthEvent("auth.otp_sent", {
|
||||||
phone: input.phoneNumber,
|
phone: input.phoneNumber,
|
||||||
success: response.status === "OK",
|
success: response.status === "OK",
|
||||||
@@ -82,7 +85,7 @@ export const withPasswordlessTelemetry =
|
|||||||
},
|
},
|
||||||
consumeCode: async (input: any) => {
|
consumeCode: async (input: any) => {
|
||||||
try {
|
try {
|
||||||
const response = await base.consumeCode(input);
|
const response = await callBase("consumeCode", input);
|
||||||
if (response.status === "OK") {
|
if (response.status === "OK") {
|
||||||
recordAuthEvent("auth.otp_consumed", {
|
recordAuthEvent("auth.otp_consumed", {
|
||||||
authUserId: response.user?.id,
|
authUserId: response.user?.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user