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

No way to skip authentication with Clerk + Remix #2940

Closed
4 tasks done
tmcw opened this issue Mar 5, 2024 · 3 comments
Closed
4 tasks done

No way to skip authentication with Clerk + Remix #2940

tmcw opened this issue Mar 5, 2024 · 3 comments
Assignees

Comments

@tmcw
Copy link

tmcw commented Mar 5, 2024

Preliminary Checks

Reproduction / Replay Link

.

Publishable key

.

Description

We've been suffering from the various remix issues and have an app that supports iframe embeds. Clerk does not work with iframe embeds at all - it produces a 401 and breaks. Ideally, Clerk wouldn't break when used inside of iframes. But, sparing that, it would be nice if we could disable Clerk for certain routes.

We got recommended to something like this:

export const loader = (args: LoaderFunctionArgs) => {
  const u = new URL(args.request.url);
  // If we're loading an embed path, skip authentication
  // because of Clerk's quality problems.
  if (u.pathname.startsWith("/embed")) {
    return loaderInner({
      ...args,
      request: {
        ...args.request,
        auth: {
          // Faking the request just in case a downstream
          // loader expects realism
          sessionClaims: {} as any,
          userId: null,
          orgId: null,
          debug: false as any,
          orgRole: null,
        } as any,
      },
    } satisfies LoaderFunctionArgsWithAuth);
  } else {
    return rootAuthLoader(args, loaderInner);
  }
};

To resolve this without an update on Clerk's end, but that produces the error message:

🔒 Clerk: Looks like you didn't pass 'clerkState' to "".
 
Use 'rootAuthLoader' as your root loader. Then, simply wrap the App component with ClerkApp and make it the default export.
Example:

So, in short:

  • Clerk doesn't work in iframes. When it renders an interstitial, it breaks the page.
  • We'd love for it to work in iframes, but if not, for it to be disable'able on specific routes, like it appears it is for Next.js

Steps to reproduce:

  1. Embed a page that uses clerk
  2. Have an expired session

Expected behavior:

Clerk shouldn't authenticate in the iframe.

Actual behavior:

It does and breaks the iframe environment

Environment

@remix-run/dev: 2.8.0 => 2.8.0
    @remix-run/eslint-config: 2.6.0 => 2.8.0
    @remix-run/node: 2.6.0 => 2.8.0
    @remix-run/react: 2.6.0 => 2.8.0
    @remix-run/serve: 2.6.0 => 2.8.0
    @clerk/backend: ^0.38.3 => 0.38.3
    @clerk/clerk-sdk-node: ^4.13.11 => 4.13.11
    @clerk/remix: ^3.1.21 => 3.1.21
@tmcw tmcw added the needs-triage A ticket that needs to be triaged by a team member label Mar 5, 2024
@jescalan jescalan removed the needs-triage A ticket that needs to be triaged by a team member label Mar 25, 2024
@jescalan jescalan added the confirmed label Mar 25, 2024 — with Linear
@iqqmuT
Copy link

iqqmuT commented Apr 12, 2024

You can prevent Clerk being in use on specific routes by skipping them in config.matcher or adding them to ignoreRoutes in middleware.js:

middleware.js

export default authMiddleware({
  // ...
  ignoredRoutes: ['/embed(.*)'],
});

https://clerk.com/docs/references/nextjs/auth-middleware#options

@tmcw
Copy link
Author

tmcw commented Apr 12, 2024

This issue is "No way to skip authentication with Clerk + Remix" - authMiddleware is a feature for the Next.js integration, not the Remix integration.

@anagstef anagstef self-assigned this Jun 10, 2024
@anagstef
Copy link
Member

Hello! This issue has been resolved with the release of Core 2, which totally replaces the Interstitial with a new mechanism that does not break inside iframes.

I'll be closing this issue as it is fixed on the latest version of @clerk/remix package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants