Skip to content

Commit

Permalink
fix(remix): Make rootAuthLoader only throw if a callback exists
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Feb 28, 2022
1 parent ca03064 commit 2689f6c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/remix/src/ssr/rootAuthLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ export async function rootAuthLoader(
cbOrOptions: any,
options?: any,
): Promise<LoaderFunctionReturn> {
const cb = typeof cbOrOptions === 'function' ? cbOrOptions : undefined;
const callback = typeof cbOrOptions === 'function' ? cbOrOptions : undefined;
const opts: RootAuthLoaderOptions = options
? options
: !!cbOrOptions && typeof cbOrOptions !== 'function'
? cbOrOptions
: {};

const { authData, interstitial } = await getAuthData(args.request, opts);

if (interstitial) {
return wrapClerkState({ __clerk_ssr_interstitial: interstitial });
}

const callbackResult = await cb?.(injectAuthIntoArgs(args, sanitizeAuthData(authData!)));
if (!callback) {
return { ...wrapClerkState({ __clerk_ssr_state: authData }) };
}

const callbackResult = await callback?.(injectAuthIntoArgs(args, sanitizeAuthData(authData!)));
assertObject(callbackResult, invalidRootLoaderCallbackReturn);

// Pass through custom responses
if (isResponse(callbackResult)) {
if (callbackResult.status >= 300 && callbackResult.status < 400) {
Expand Down

0 comments on commit 2689f6c

Please sign in to comment.