Skip to content

Commit

Permalink
feat(clerk-remix): Introduce SSR getAuth for Remix
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Feb 28, 2022
1 parent 23a10c7 commit bae06b8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/remix/src/ssr/getAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { noRequestPassedInGetAuth } from '../errors';
import { getAuthData } from './getAuthData';
import { GetAuthOptions, GetAuthReturn, LoaderFunctionArgs } from './types';
import { sanitizeAuthData } from './utils';

export async function getAuth<Options extends GetAuthOptions>(
argsOrReq: Request | LoaderFunctionArgs,
options?: Options,
): GetAuthReturn<Options> {
if (!argsOrReq) {
throw new Error(noRequestPassedInGetAuth);
}

const request = 'request' in argsOrReq ? argsOrReq.request : argsOrReq;
const { authData } = await getAuthData(request, options || {});
// @ts-expect-error This can only return null during interstitial,
// but the public types should not know that
return sanitizeAuthData(authData || {});
}

0 comments on commit bae06b8

Please sign in to comment.