Fix Cypress Clerk OTP helper for same-origin SignIn
This commit is contained in:
@@ -53,11 +53,9 @@ Cypress.Commands.add("loginWithClerkOtp", () => {
|
|||||||
// Cypress cannot reliably drive Clerk modal/iframe flows.
|
// Cypress cannot reliably drive Clerk modal/iframe flows.
|
||||||
cy.visit("/sign-in");
|
cy.visit("/sign-in");
|
||||||
|
|
||||||
// The Clerk UI is hosted on a different origin.
|
// Clerk SignIn can render on our app origin (localhost) or redirect to Clerk-hosted UI,
|
||||||
cy.origin(
|
// depending on config/version. Handle both.
|
||||||
opts.clerkOrigin,
|
const fillOtpFlow = (email: string, otp: string) => {
|
||||||
{ args: { email: opts.email, otp: opts.otp } },
|
|
||||||
({ email, otp }) => {
|
|
||||||
cy.get(
|
cy.get(
|
||||||
'input[type="email"], input[name="identifier"], input[autocomplete="email"]',
|
'input[type="email"], input[name="identifier"], input[autocomplete="email"]',
|
||||||
{ timeout: 20_000 },
|
{ timeout: 20_000 },
|
||||||
@@ -89,8 +87,21 @@ Cypress.Commands.add("loginWithClerkOtp", () => {
|
|||||||
.click({ force: true });
|
.click({ force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
cy.location("origin", { timeout: 20_000 }).then((origin) => {
|
||||||
|
if (origin === opts.clerkOrigin) {
|
||||||
|
cy.origin(
|
||||||
|
opts.clerkOrigin,
|
||||||
|
{ args: { email: opts.email, otp: opts.otp } },
|
||||||
|
({ email, otp }) => {
|
||||||
|
fillOtpFlow(email, otp);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
fillOtpFlow(opts.email, opts.otp);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
Reference in New Issue
Block a user