From 30fcdd51a98dea60da36f2b5152ea22405d2c4f2 Mon Sep 17 00:00:00 2001 From: George Desipris <73396808+desiprisg@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:37:43 +0300 Subject: [PATCH] feat(remix,backend): Repo level config for remix (#1470) * feat(remix,backend): Repo level config for remix * fix(remix): Remove unused utility * fix(remix): Add ClerkState missing types * test(backend,remix): Update tests * chore(repo): Changeset --- .changeset/nine-peas-care.md | 5 ++ .changeset/wicked-schools-tell.md | 5 ++ packages/backend/src/tokens/authStatus.ts | 48 +++++++++++++++++-- packages/backend/src/tokens/request.test.ts | 15 ++++++ packages/backend/src/tokens/request.ts | 3 ++ .../src/utils/mergeNextClerkPropsWithEnv.ts | 2 +- .../remix/src/client/RemixClerkProvider.tsx | 6 +++ packages/remix/src/client/types.ts | 3 ++ packages/remix/src/ssr/authenticateRequest.ts | 18 +++++++ packages/remix/src/ssr/types.ts | 3 ++ packages/remix/src/ssr/utils.ts | 3 ++ 11 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 .changeset/nine-peas-care.md create mode 100644 .changeset/wicked-schools-tell.md diff --git a/.changeset/nine-peas-care.md b/.changeset/nine-peas-care.md new file mode 100644 index 0000000000..226a0c54c6 --- /dev/null +++ b/.changeset/nine-peas-care.md @@ -0,0 +1,5 @@ +--- +'@clerk/remix': minor +--- + +Configure sign in/up and afterSignIn/Up paths for remix via env variables. diff --git a/.changeset/wicked-schools-tell.md b/.changeset/wicked-schools-tell.md new file mode 100644 index 0000000000..ed7ac323b3 --- /dev/null +++ b/.changeset/wicked-schools-tell.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': minor +--- + +Include `signUpUrl`, `afterSignInUrl` and `afterSignUpUrl` to `authenticateRequest` options. diff --git a/packages/backend/src/tokens/authStatus.ts b/packages/backend/src/tokens/authStatus.ts index 413691552f..953a028d41 100644 --- a/packages/backend/src/tokens/authStatus.ts +++ b/packages/backend/src/tokens/authStatus.ts @@ -22,6 +22,9 @@ export type SignedInState = { isSatellite: boolean; domain: string; signInUrl: string; + signUpUrl: string; + afterSignInUrl: string; + afterSignUpUrl: string; isSignedIn: true; isInterstitial: false; isUnknown: false; @@ -38,6 +41,9 @@ export type SignedOutState = { isSatellite: boolean; domain: string; signInUrl: string; + signUpUrl: string; + afterSignInUrl: string; + afterSignUpUrl: string; isSignedIn: false; isInterstitial: false; isUnknown: false; @@ -94,6 +100,9 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis loadUser, loadOrganization, signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, } = options as any; const { sid: sessionId, org_id: orgId, sub: userId } = sessionClaims; @@ -143,6 +152,9 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis domain, isSatellite, signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, isSignedIn: true, isInterstitial: false, isUnknown: false, @@ -151,7 +163,17 @@ export async function signedIn(options: T, sessionClaims: JwtPayload): Promis } export function signedOut(options: T, reason: AuthReason, message = ''): SignedOutState { - const { frontendApi, publishableKey, proxyUrl, isSatellite, domain, signInUrl } = options as any; + const { + frontendApi, + publishableKey, + proxyUrl, + isSatellite, + domain, + signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, + } = options as any; return { status: AuthStatus.SignedOut, @@ -163,6 +185,9 @@ export function signedOut(options: T, reason: AuthReason, message = ''): Sign isSatellite, domain, signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, isSignedIn: false, isInterstitial: false, isUnknown: false, @@ -171,7 +196,17 @@ export function signedOut(options: T, reason: AuthReason, message = ''): Sign } export function interstitial(options: T, reason: AuthReason, message = ''): InterstitialState { - const { frontendApi, publishableKey, proxyUrl, isSatellite, domain, signInUrl } = options as any; + const { + frontendApi, + publishableKey, + proxyUrl, + isSatellite, + domain, + signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, + } = options as any; return { status: AuthStatus.Interstitial, reason, @@ -182,6 +217,9 @@ export function interstitial(options: T, reason: AuthReason, message = ''): I domain, proxyUrl, signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, isSignedIn: false, isInterstitial: true, isUnknown: false, @@ -190,7 +228,8 @@ export function interstitial(options: T, reason: AuthReason, message = ''): I } export function unknownState(options: T, reason: AuthReason, message = ''): UnknownState { - const { frontendApi, publishableKey, isSatellite, domain, signInUrl } = options as any; + const { frontendApi, publishableKey, isSatellite, domain, signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = + options as any; return { status: AuthStatus.Unknown, reason, @@ -200,6 +239,9 @@ export function unknownState(options: T, reason: AuthReason, message = ''): U isSatellite, domain, signInUrl, + signUpUrl, + afterSignInUrl, + afterSignUpUrl, isSignedIn: false, isInterstitial: false, isUnknown: true, diff --git a/packages/backend/src/tokens/request.test.ts b/packages/backend/src/tokens/request.test.ts index a968426574..219b6532b3 100644 --- a/packages/backend/src/tokens/request.test.ts +++ b/packages/backend/src/tokens/request.test.ts @@ -30,6 +30,9 @@ function assertSignedOut( isUnknown: false, isSatellite: false, signInUrl: '', + signUpUrl: '', + afterSignInUrl: '', + afterSignUpUrl: '', domain: '', message: '', toAuth: {}, @@ -72,6 +75,9 @@ function assertInterstitial( isUnknown: false, isSatellite: false, signInUrl: '', + signUpUrl: '', + afterSignInUrl: '', + afterSignUpUrl: '', domain: '', toAuth: {}, ...expectedState, @@ -88,6 +94,9 @@ function assertUnknown(assert, requestState: RequestState, reason: AuthReason) { isUnknown: true, isSatellite: false, signInUrl: '', + signUpUrl: '', + afterSignInUrl: '', + afterSignUpUrl: '', domain: '', reason, toAuth: {}, @@ -128,6 +137,9 @@ function assertSignedIn( isUnknown: false, isSatellite: false, signInUrl: '', + signUpUrl: '', + afterSignInUrl: '', + afterSignUpUrl: '', domain: '', ...expectedState, }); @@ -150,6 +162,9 @@ export default (QUnit: QUnit) => { skipJwksCache: true, isSatellite: false, signInUrl: '', + signUpUrl: '', + afterSignInUrl: '', + afterSignUpUrl: '', domain: '', searchParams: new URLSearchParams(), } satisfies AuthenticateRequestOptions; diff --git a/packages/backend/src/tokens/request.ts b/packages/backend/src/tokens/request.ts index a60e25824e..127759272e 100644 --- a/packages/backend/src/tokens/request.ts +++ b/packages/backend/src/tokens/request.ts @@ -101,6 +101,9 @@ export type AuthenticateRequestOptions = OptionalVerifyTokenOptions & * @experimental */ signInUrl?: string; + signUpUrl?: string; + afterSignInUrl?: string; + afterSignUpUrl?: string; request?: Request; }; diff --git a/packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts b/packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts index de7fb64325..4c2015aa34 100644 --- a/packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts +++ b/packages/nextjs/src/utils/mergeNextClerkPropsWithEnv.ts @@ -14,5 +14,5 @@ export const mergeNextClerkPropsWithEnv = (props: Omit & MultiDomainAndOrProxy; diff --git a/packages/remix/src/ssr/utils.ts b/packages/remix/src/ssr/utils.ts index 826be5e352..81c33ec980 100644 --- a/packages/remix/src/ssr/utils.ts +++ b/packages/remix/src/ssr/utils.ts @@ -110,6 +110,9 @@ export const injectRequestStateIntoResponse = async (response: Response, request __domain: requestState.domain, __isSatellite: requestState.isSatellite, __signInUrl: requestState.signInUrl, + __signUpUrl: requestState.signUpUrl, + __afterSignInUrl: requestState.afterSignInUrl, + __afterSignUpUrl: requestState.afterSignUpUrl, __clerk_debug: debugRequestState(requestState), __clerkJSUrl: getEnvVariable('CLERK_JS'), __clerkJSVersion: getEnvVariable('CLERK_JS_VERSION'),