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

Remix Server Side Auth #90

Open
stephen776 opened this issue Oct 4, 2024 · 4 comments
Open

Remix Server Side Auth #90

stephen776 opened this issue Oct 4, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@stephen776
Copy link

Is there a plan to implement SSA for Remix?

@sshader sshader added the enhancement New feature or request label Oct 9, 2024
@sshader
Copy link
Contributor

sshader commented Oct 9, 2024

No immediate plans -- current focus is on React + Next.js. SSA support for Next.js is still experimental, so that would need to stabilize before tackling SSA for other frameworks

@jamalsoueidan
Copy link

Waiting for this :)

@thomasballinger
Copy link
Contributor

thomasballinger commented Dec 2, 2024

In the Next.js implementation the cookie is set in https://github.com/get-convex/convex-auth/blob/main/src/nextjs/server/cookies.ts#L75 in the Next.js implementation because it sets cookies https://github.com/get-convex/convex-auth/blob/main/src/nextjs/server/index.tsx#L250-L254

@developerdanwu
Copy link

developerdanwu commented Dec 4, 2024

Hi guys! I really enjoy using convex and convex auth and I would also love to see this implemented. I had a brief chat with @thomasballinger on discord about this issue. (thread here) Essentially, as Remix users, we need a way to fetch the token in the loader so we can access authenticated APIs from there.

I experimented with using the primitives provided by Convex Auth to create a component that handles authentication on the client-side, hoping to still leverage Remix's server mode while keeping the authentication logic in the client. Here's an example of the component I created:

export function Authenticated({ children }: { children: React.ReactNode }) {
  const { generatePath } = useLocale();

  return (
    <>
      <AuthLoading>
        <div className={"flex justify-center items-center h-screen"}>
          <LoadingSpinner size={36} />
        </div>
      </AuthLoading>
      <ConvexUnauthenticated>
        <Navigate to={generatePath(routes.signIn)} />
      </ConvexUnauthenticated>
      <ConvexAuthenticated>
        <AuthenticatedProvider>{children}</AuthenticatedProvider>
      </ConvexAuthenticated>
    </>
  );
}

While this approach works in SPA mode, it triggers an error and some unexpected behaviors when running in server mode, as shown in the screenshot below:

Nov 30 Screenshot 2920x186

Sadly running in SPA mode is blocking me from using some libs such as remix-i18next which depend on the loader

Has anyone else tried to implement client auth handling in remix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants