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
9 changes: 9 additions & 0 deletions .changeset/long-icons-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'gatsby-plugin-clerk': major
---

Drop deprecations. Migration steps:
- use `CLERK_SECRET_KEY` instead of `CLERK_API_KEY` env variable
- use `secretKey` instead of `apiKey`
- use `GATSBY_CLERK_PUBLISHABLE_KEY` instead of `GATSBY_CLERK_FRONTEND_API` env variable
- use `publishableKey` instead of `frontendApi`
16 changes: 0 additions & 16 deletions packages/gatsby-plugin-clerk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { deprecated } from '@clerk/shared/deprecated';

export const API_URL = process.env.CLERK_API_URL || 'https://api.clerk.com';
export const API_VERSION = process.env.CLERK_API_VERSION || 'v1';
/**
* @deprecated Use `CLERK_SECRET_KEY` instead.
*/
export const API_KEY = process.env.CLERK_API_KEY || '';
if (API_KEY) {
deprecated('CLERK_API_KEY', 'Use `CLERK_SECRET_KEY` environment variable instead.');
}
export const SECRET_KEY = process.env.CLERK_SECRET_KEY || '';
/**
* @deprecated Use `PUBLISHABLE_KEY` instead.
*/
export const FRONTEND_API = process.env.GATSBY_CLERK_FRONTEND_API || '';
if (FRONTEND_API) {
deprecated('FRONTEND_API', 'Use `PUBLISHABLE_KEY` environment variable instead.');
}
export const PUBLISHABLE_KEY = process.env.GATSBY_CLERK_PUBLISHABLE_KEY || '';

export const CLERK_JS = process.env.GATSBY_CLERK_JS;
Expand Down
5 changes: 1 addition & 4 deletions packages/gatsby-plugin-clerk/src/gatsby-browser.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import type { GatsbyBrowser } from 'gatsby';
import React from 'react';

import { CLERK_JS, FRONTEND_API, PROXY_URL, PUBLISHABLE_KEY } from './constants';
import { CLERK_JS, PROXY_URL, PUBLISHABLE_KEY } from './constants';
import { ClerkProvider } from './GatsbyClerkProvider';

export const wrapPageElement: GatsbyBrowser['wrapPageElement'] = ({ element, props }, pluginOptions) => {
Expand All @@ -13,9 +12,7 @@ export const wrapPageElement: GatsbyBrowser['wrapPageElement'] = ({ element, pro
}

return (
// @ts-expect-error
<ClerkProvider
frontendApi={FRONTEND_API || ''}
publishableKey={PUBLISHABLE_KEY || ''}
clerkJSUrl={CLERK_JS}
proxyUrl={PROXY_URL}
Expand Down
5 changes: 1 addition & 4 deletions packages/gatsby-plugin-clerk/src/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import type { GatsbySSR } from 'gatsby';
import React from 'react';

import { CLERK_JS, FRONTEND_API, PROXY_URL, PUBLISHABLE_KEY } from './constants';
import { CLERK_JS, PROXY_URL, PUBLISHABLE_KEY } from './constants';
import { ClerkProvider } from './GatsbyClerkProvider';

export const wrapPageElement: GatsbySSR['wrapPageElement'] = ({ element, props }, pluginOptions) => {
Expand All @@ -13,9 +12,7 @@ export const wrapPageElement: GatsbySSR['wrapPageElement'] = ({ element, props }
}

return (
// @ts-expect-error
<ClerkProvider
frontendApi={FRONTEND_API}
publishableKey={PUBLISHABLE_KEY}
clerkJSUrl={CLERK_JS}
proxyUrl={PROXY_URL}
Expand Down
6 changes: 2 additions & 4 deletions packages/gatsby-plugin-clerk/src/ssr/authenticateRequest.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import type { GetServerDataProps } from 'gatsby';

import { API_KEY, FRONTEND_API, PUBLISHABLE_KEY, SECRET_KEY } from '../constants';
import { PUBLISHABLE_KEY, SECRET_KEY } from '../constants';
import { clerkClient, constants, createIsomorphicRequest } from './clerkClient';
import type { WithServerAuthOptions } from './types';

export function authenticateRequest(context: GetServerDataProps, options: WithServerAuthOptions) {
return clerkClient.authenticateRequest({
...options,
apiKey: API_KEY,
secretKey: SECRET_KEY,
frontendApi: FRONTEND_API,
publishableKey: PUBLISHABLE_KEY,
request: createIsomorphicRequest((Request, Headers) => {
const headers = new Headers(Object.fromEntries(context.headers) as Record<string, string>);
Expand Down Expand Up @@ -38,7 +36,7 @@ const returnReferrerAsXForwardedHostToFixLocalDevGatsbyProxy = (headers: Map<str
const referrerUrl = new URL(headers.get(constants.Headers.Referrer) as string);
const hostUrl = new URL('https://' + (headers.get(constants.Headers.Host) as string));

if (isDevelopmentOrStaging(SECRET_KEY || API_KEY || '') && hostUrl.hostname === referrerUrl.hostname) {
if (isDevelopmentOrStaging(SECRET_KEY || '') && hostUrl.hostname === referrerUrl.hostname) {
return referrerUrl.host;
}

Expand Down
6 changes: 2 additions & 4 deletions packages/gatsby-plugin-clerk/src/ssr/clerkClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { Clerk } from '@clerk/backend';

import { API_KEY, API_URL, API_VERSION, SECRET_KEY } from '../constants';
import { API_URL, API_VERSION, SECRET_KEY } from '../constants';

const clerkClient = Clerk({
apiKey: API_KEY,
secretKey: SECRET_KEY,
apiUrl: API_URL,
apiVersion: API_VERSION,
Expand All @@ -14,6 +12,6 @@ const clerkClient = Clerk({

const createClerkClient = Clerk;

export { clerkClient, createClerkClient, Clerk };
export { Clerk, clerkClient, createClerkClient };

export * from '@clerk/backend';
5 changes: 3 additions & 2 deletions packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GetServerDataProps, GetServerDataReturn } from 'gatsby';

import { FRONTEND_API, PUBLISHABLE_KEY } from '../constants';
import { PUBLISHABLE_KEY } from '../constants';
import { authenticateRequest } from './authenticateRequest';
import { clerkClient, constants } from './clerkClient';
import type { WithServerAuthCallback, WithServerAuthOptions, WithServerAuthResult } from './types';
Expand All @@ -25,8 +25,9 @@ export const withServerAuth: WithServerAuth = (cbOrOptions: any, options?: any):
[constants.Headers.AuthMessage]: requestState.message,
[constants.Headers.AuthStatus]: requestState.status,
};
// TODO(@dimkl): use empty string for frontendApi until type is fixed in @clerk/backend to drop it
const interstitialHtml = clerkClient.localInterstitial({
frontendApi: FRONTEND_API,
frontendApi: '',
publishableKey: PUBLISHABLE_KEY,
});
return injectSSRStateIntoProps({ headers }, { __clerk_ssr_interstitial_html: interstitialHtml });
Expand Down