Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clerk core v2 - Clerk fails to load under cypress iframe - "Browser unauthenticated" #3369

Closed
4 tasks done
AlonMiz opened this issue May 11, 2024 · 3 comments
Closed
4 tasks done
Labels
needs-reproduction Awaiting a minimal reproduction

Comments

@AlonMiz
Copy link

AlonMiz commented May 11, 2024

Preliminary Checks

Reproduction

https://github.com/clerk/example-cypress-nextjs

Publishable key

pk_test_cHJvcGVyLXNwYXJyb3ctNDkuY2xlcmsuYWNjb3VudHMuZGV2JA

Description

Im struggling with upgrading to the latest clerk. i already migrated the app to the new core, but all of my e2e tests are broken now.

Steps to reproduce:

  1. Upgrading to latest Clerk
  2. run e2e tests

Expected behavior:

tests should work as before

Actual behavior:

tests are failing with cookie issues

{
    "errors": [
        {
            "message": "Browser unauthenticated",
            "long_message": "Unable to authenticate this browser for your development instance. Check your Clerk cookies and try again. If the issue persists reach out to support@clerk.com.",
            "code": "dev_browser_unauthenticated"
        }
    ],
    "clerk_trace_id": "7d1c50d0956fd9d3fcf0e724ee113c37"
}

    "@clerk/clerk-sdk-node": "5.0.0",
    "@clerk/nextjs": "5.0.1",
    "@clerk/themes": "2.0.0",
    "next": "14.2.2",

exception

Uncaught (in promise) Error: ClerkJS: Something went wrong initializing Clerk.
    at o (VM2800 clerk.browser.js:2:73614)
    at $e.<anonymous> (VM2800 clerk.browser.js:2:223897)
    at async $e.load (VM2800 clerk.browser.js:2:202798)
    at async _IsomorphicClerk.loadClerkJS (VM2822 node_modules_@clerk_clerk-react_dist_51047c._.js:1728:17)

sign in method

Cypress.Commands.add(`signIn`, () => {
  cy.log(`Signing in.`);
  cy.setCookie(languageUtils.languageCookieKey, 'he');
  cy.visit('/');

  cy.window().should((win) => {
    expect(win).to.not.have.property(`Clerk`, undefined);
    expect(win.Clerk?.loaded).to.eq(true);
  });
  cy.window().then((win) => {
    cy.clearCookies({ domain: win.location.host });
    cy.log(`Clear cookies.`);
  });
  cy.window().then(async (win) => {
    cy.log(`Creating user.`);
    await win.Clerk.signOut();
    const res = await win.Clerk.client?.signIn.create({
      identifier: 'clerk_test@example.com',
      password: 'asdqwe123',
    });
    cy.log(`Signing in.`);
    await win.Clerk?.setActive?.({
      session: res?.createdSessionId,
    });
    cy.log(`Finished Signing in.`);
  });
});

Environment

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 59.81 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.volta/tools/image/node/20.11.0/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 10.2.4 - ~/.volta/tools/image/node/20.11.0/bin/npm
    pnpm: 8.5.0 - ~/Library/pnpm/pnpm
    bun: 1.0.1 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 106.1.44.105
    Chrome: 124.0.6367.158
    Safari: 17.4.1
  npmPackages:
    @clerk/clerk-sdk-node: 5.0.5 => 5.0.5
    @clerk/nextjs: 5.0.8 => 5.0.8
    @clerk/themes: 2.1.3 => 2.1.3
    cypress: 13.9.0 => 13.9.0
    next: 14.2.3 => 14.2.3
    react: 18.3.1 => 18.3.1
    react-dom: 18.3.1 => 18.3.1
@AlonMiz AlonMiz added the needs-triage A ticket that needs to be triaged by a team member label May 11, 2024
@LekoArts LekoArts added needs-reproduction Awaiting a minimal reproduction and removed needs-triage A ticket that needs to be triaged by a team member labels May 13, 2024
@LekoArts
Copy link
Member

Hi!

I think this could be fixed by #3245 but it wasn't released yet to autoload for everyone.

Can you change your <ClerkProvider> inside your Next.js application to the following?

<ClerkProvider clerkJSVersion="5.2.3-snapshot.v47a3ff9">

And then try again? This would be a temporary test of the new version to see if it works.

@LekoArts
Copy link
Member

#3245 was released now. Please retry again with latest versions.

@AlonMiz
Copy link
Author

AlonMiz commented May 13, 2024

Thanks @LekoArts it does work now 🥳
ill update if anything goes wrong 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reproduction Awaiting a minimal reproduction
Projects
None yet
Development

No branches or pull requests

2 participants