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.
|
||||
cy.visit("/sign-in");
|
||||
|
||||
// The Clerk UI is hosted on a different origin.
|
||||
cy.origin(
|
||||
opts.clerkOrigin,
|
||||
{ args: { email: opts.email, otp: opts.otp } },
|
||||
({ email, otp }) => {
|
||||
// Clerk SignIn can render on our app origin (localhost) or redirect to Clerk-hosted UI,
|
||||
// depending on config/version. Handle both.
|
||||
const fillOtpFlow = (email: string, otp: string) => {
|
||||
cy.get(
|
||||
'input[type="email"], input[name="identifier"], input[autocomplete="email"]',
|
||||
{ timeout: 20_000 },
|
||||
@@ -89,8 +87,21 @@ Cypress.Commands.add("loginWithClerkOtp", () => {
|
||||
.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 {
|
||||
|
||||
Reference in New Issue
Block a user