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

feat(remix): Support handshake flow for remix #2380

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-chairs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/remix': minor
---

Update the Remix rootAuthLoader to handle handshake auth status, this replaces the previous interstitial flow.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's include a short migration guide as the ClerkErrorBoundary export is no longer needed :)

2 changes: 1 addition & 1 deletion packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const authMiddleware: AuthMiddleware = (...args: unknown[]) => {
}

if (requestState.status === AuthStatus.Handshake) {
throw new Error('Unexpected handshake without redirect');
throw new Error('Clerk: unexpected handshake without redirect');
}

const auth = Object.assign(requestState.toAuth(), {
Expand Down
10 changes: 7 additions & 3 deletions packages/remix/src/ssr/rootAuthLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AuthStatus, sanitizeAuthObject } from '@clerk/backend/internal';
import type { defer } from '@remix-run/server-runtime';
import { redirect } from '@remix-run/server-runtime';
import { isDeferredData } from '@remix-run/server-runtime/dist/responses';

import { invalidRootLoaderCallbackReturn } from '../errors';
Expand Down Expand Up @@ -50,9 +49,14 @@ export const rootAuthLoader: RootAuthLoader = async (

const requestState = await authenticateRequest(args, opts);

// TODO handle handshake
const hasLocationHeader = requestState.headers.get('location');
if (hasLocationHeader) {
// triggering a handshake redirect
return new Response(null, { status: 307, headers: requestState.headers });
}

if (requestState.status === AuthStatus.Handshake) {
throw redirect('');
throw new Error('Clerk: unexpected handshake without redirect');
}

if (!handler) {
Expand Down
Loading