Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 0 additions & 22 deletions packages/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ This package provides Clerk Backend API resources and low-level authentication u
- Support multiple CLERK_API_KEY for multiple instance REST access.
- Align JWT key resolution algorithm across all environments (Function param > Environment variable > JWKS from API).
- Tested automatically across different runtimes (Node, CF Workers, Vercel Edge middleware.)
- Clean up Clerk interstitial logic.
- Refactor the Rest Client API to return `{data, errors}` instead of throwing errors.
- Export a generic verifyToken for Clerk JWTs verification.
- Align AuthData interface for SSR.
Expand Down Expand Up @@ -80,7 +79,6 @@ clerk.allowlistIdentifiers;
clerk.clients;
clerk.emailAddresses;
clerk.emails;
clerk.interstitial;
clerk.invitations;
clerk.organizations;
clerk.phoneNumbers;
Expand All @@ -96,12 +94,6 @@ clerk.authenticateRequest(options);

// Build debug payload of the request state.
clerk.debugRequestState(requestState);

// Load clerk interstitial from this package
clerk.localInterstitial(options);

// Load clerk interstitial from the public Private API endpoint (Deprecated)
clerk.remotePrivateInterstitial(options);
```

#### verifyToken(token: string, options: VerifyTokenOptions)
Expand Down Expand Up @@ -161,20 +153,6 @@ import { debugRequestState } from '@clerk/backend';
debugRequestState(requestState);
```

#### loadInterstitialFromLocal(options)

Generates a debug payload for the request state. The debug payload is available via `window.__clerk_debug`.

```js
import { loadInterstitialFromLocal } from '@clerk/backend';

loadInterstitialFromLocal({
frontendApi: '...',
clerkJSVersion: '...',
debugData: {},
});
```

#### signedInAuthObject(sessionClaims, options)

Builds the AuthObject when the user is signed in.
Expand Down
21 changes: 0 additions & 21 deletions packages/backend/src/api/endpoints/InterstitialApi.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/backend/src/api/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from './ClientApi';
export * from './DomainApi';
export * from './EmailAddressApi';
export * from './EmailApi';
export * from './InterstitialApi';
export * from './InvitationApi';
export * from './OrganizationApi';
export * from './PhoneNumberApi';
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DomainAPI,
EmailAddressAPI,
EmailAPI,
InterstitialAPI,
InvitationAPI,
OrganizationAPI,
PhoneNumberAPI,
Expand All @@ -27,7 +26,6 @@ export function createBackendApiClient(options: CreateBackendApiOptions) {
clients: new ClientAPI(request),
emailAddresses: new EmailAddressAPI(request),
emails: new EmailAPI(request),
interstitial: new InterstitialAPI(request),
invitations: new InvitationAPI(request),
organizations: new OrganizationAPI(request),
phoneNumbers: new PhoneNumberAPI(request),
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default (QUnit: QUnit) => {
'decodeJwt',
'deserialize',
'hasValidSignature',
'loadInterstitialFromLocal',
'makeAuthObjectSerializable',
'prunePrivateMetadata',
'redirect',
Expand Down
95 changes: 1 addition & 94 deletions packages/backend/src/tokens/authStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import type { TokenVerificationErrorReason } from './errors';
export enum AuthStatus {
SignedIn = 'signed-in',
SignedOut = 'signed-out',
Interstitial = 'interstitial',
Handshake = 'handshake',
Unknown = 'unknown',
SessionTokenOutdated = 'SessionTokenOutdated',
}

Expand All @@ -27,8 +25,6 @@ export type SignedInState = {
afterSignInUrl: string;
afterSignUpUrl: string;
isSignedIn: true;
isInterstitial: false;
isUnknown: false;
toAuth: () => SignedInAuthObject;
headers: Headers;
};
Expand All @@ -46,31 +42,16 @@ export type SignedOutState = {
afterSignInUrl: string;
afterSignUpUrl: string;
isSignedIn: false;
isInterstitial: false;
isUnknown: false;
toAuth: () => SignedOutAuthObject;
headers: Headers;
};

export type InterstitialState = Omit<SignedOutState, 'isInterstitial' | 'status' | 'toAuth'> & {
status: AuthStatus.Interstitial;
isInterstitial: true;
toAuth: () => null;
};

export type HandshakeState = Omit<SignedOutState, 'status' | 'toAuth'> & {
status: AuthStatus.Handshake;
headers: Headers;
isInterstitial: false;
toAuth: () => null;
};

export type UnknownState = Omit<InterstitialState, 'status' | 'isInterstitial' | 'isUnknown'> & {
status: AuthStatus.Unknown;
isInterstitial: false;
isUnknown: true;
};

export enum AuthErrorReason {
DevBrowserSync = 'dev-browser-sync',
SessionTokenMissing = 'session-token-missing',
Expand Down Expand Up @@ -98,7 +79,7 @@ export enum AuthErrorReason {

export type AuthReason = AuthErrorReason | TokenVerificationErrorReason;

export type RequestState = SignedInState | SignedOutState | InterstitialState | HandshakeState | UnknownState;
export type RequestState = SignedInState | SignedOutState | HandshakeState;

type LoadResourcesOptions = {
loadSession?: boolean;
Expand Down Expand Up @@ -200,8 +181,6 @@ export async function signedIn<T extends AuthStatusOptionsType>(
afterSignInUrl,
afterSignUpUrl,
isSignedIn: true,
isInterstitial: false,
isUnknown: false,
toAuth: () => authObject,
headers,
};
Expand Down Expand Up @@ -236,49 +215,11 @@ export function signedOut<T extends AuthStatusOptionsType>(
afterSignInUrl,
afterSignUpUrl,
isSignedIn: false,
isInterstitial: false,
isUnknown: false,
headers,
toAuth: () => signedOutAuthObject({ ...options, status: AuthStatus.SignedOut, reason, message }),
};
}

export function interstitial<T extends AuthStatusOptionsType>(
options: T,
reason: AuthReason,
message = '',
): InterstitialState {
const {
publishableKey = '',
proxyUrl = '',
isSatellite = false,
domain = '',
signInUrl = '',
signUpUrl = '',
afterSignInUrl = '',
afterSignUpUrl = '',
} = options;

return {
status: AuthStatus.Interstitial,
reason,
message,
publishableKey,
isSatellite,
domain,
proxyUrl,
signInUrl,
signUpUrl,
afterSignInUrl,
afterSignUpUrl,
isSignedIn: false,
isInterstitial: true,
isUnknown: false,
toAuth: () => null,
headers: new Headers(),
};
}

export function handshake<T extends AuthStatusOptionsType>(
options: T,
reason: AuthReason,
Expand Down Expand Up @@ -309,41 +250,7 @@ export function handshake<T extends AuthStatusOptionsType>(
afterSignInUrl,
afterSignUpUrl,
isSignedIn: false,
isUnknown: false,
headers,
isInterstitial: false,
toAuth: () => null,
};
}

export function unknownState(options: AuthStatusOptionsType, reason: AuthReason, message = ''): UnknownState {
const {
publishableKey = '',
proxyUrl = '',
isSatellite = false,
domain = '',
signInUrl = '',
signUpUrl = '',
afterSignInUrl = '',
afterSignUpUrl = '',
} = options;

return {
status: AuthStatus.Unknown,
reason,
message,
publishableKey,
isSatellite,
domain,
proxyUrl,
signInUrl,
signUpUrl,
afterSignInUrl,
afterSignUpUrl,
isSignedIn: false,
isInterstitial: false,
isUnknown: true,
toAuth: () => null,
headers: new Headers(),
};
}
2 changes: 0 additions & 2 deletions packages/backend/src/tokens/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export enum TokenVerificationErrorReason {
RemoteJWKMissing = 'jwk-remote-missing',

JWKFailedToResolve = 'jwk-failed-to-resolve',

RemoteInterstitialFailedToLoad = 'interstitial-remote-failed-to-load',
}

export enum TokenVerificationErrorAction {
Expand Down
13 changes: 0 additions & 13 deletions packages/backend/src/tokens/factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ApiClient } from '../api';
import { mergePreDefinedOptions } from '../util/mergePreDefinedOptions';
import type { LoadInterstitialOptions } from './interstitial';
import { loadInterstitialFromLocal } from './interstitial';
import type { AuthenticateRequestOptions } from './request';
import { authenticateRequest as authenticateRequestOriginal, debugRequestState } from './request';

Expand Down Expand Up @@ -40,7 +38,6 @@ export type CreateAuthenticateRequestOptions = {
};

export function createAuthenticateRequest(params: CreateAuthenticateRequestOptions) {
const { apiClient } = params;
const buildTimeOptions = mergePreDefinedOptions(defaultOptions, params.options);

const authenticateRequest = (request: Request, options: RunTimeOptions = {}) => {
Expand All @@ -56,18 +53,8 @@ export function createAuthenticateRequest(params: CreateAuthenticateRequestOptio
});
};

const localInterstitial = (options: Omit<LoadInterstitialOptions, 'apiUrl'>) => {
const runTimeOptions = mergePreDefinedOptions(buildTimeOptions, options);
return loadInterstitialFromLocal({ ...options, ...runTimeOptions });
};

// TODO: Replace this function with remotePublicInterstitial
const remotePrivateInterstitial = () => apiClient.interstitial.getInterstitial();

return {
authenticateRequest,
localInterstitial,
remotePrivateInterstitial,
debugRequestState,
};
}
1 change: 0 additions & 1 deletion packages/backend/src/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ export { AuthStatus } from './authStatus';
export type { RequestState } from './authStatus';
export * from './errors';
export * from './factory';
export { loadInterstitialFromLocal } from './interstitial';
export { debugRequestState } from './request';
export type { AuthenticateRequestOptions, OptionalVerifyTokenOptions } from './request';
Loading