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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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/wise-onions-double.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
---
"@clerk/fastify": major
---

Recently Fastify released its v5 and along with it came some breaking changes. Read their [migration guide](https://fastify.dev/docs/latest/Guides/Migration-Guide-V5/) to learn more.

In order to support Fastify v5 a new major version of `@clerk/fastify` is required as Fastify's Node.js requirement is now `>=20`. Previously `@clerk/fastify` allowed `>=18.17.0`.

`@clerk/fastify@2.0.0` only supports Fastify v5 or later, if you want/need to continue using Fastify v4, please stick with your current version. The `@clerk/fastify@2.0.0` upgrade itself doesn't have any required code changes as only internal dependencies and requirements were updated.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,7 +115,7 @@ jobs:
run: |
if [ "${{ matrix.node-version }}" == "18" ]; then
echo "Running tests on Node 18 only for packages with LTS support."
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/fastify" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
npx turbo test $TURBO_ARGS --filter="@clerk/astro" --filter="@clerk/backend" --filter="@clerk/express" --filter="@clerk/nextjs" --filter="@clerk/clerk-react" --filter="@clerk/clerk-sdk-node" --filter="@clerk/shared" --filter="@clerk/remix" --filter="@clerk/tanstack-start" --filter="@clerk/elements"
else
echo "Running tests for all packages on Node 20."
npx turbo test $TURBO_ARGS
Expand Down
4,415 changes: 1,510 additions & 2,905 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,8 +80,6 @@
"eslint": "^8.49.0",
"execa": "^5.1.1",
"expect-type": "^0.16.0",
"fastify": "4.12.0",
"fastify-plugin": "^4.5.0",
"fs-extra": "^11.1.1",
"get-port": "^5.1.1",
"globby": "^13.2.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fastify/README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,8 +31,8 @@

### Prerequisites

- Fastify `^4.0.0` or later
- Node.js `>=18.17.0` or later
- Fastify `^5.0.0` or later
- Node.js `>=20.0.0` or later
- An existing Clerk application. [Create your account for free](https://dashboard.clerk.com/sign-up?utm_source=github&utm_medium=clerk_fastify).

### Installation
Expand Down
11 changes: 6 additions & 5 deletions packages/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,20 +43,21 @@
"@clerk/backend": "1.13.8",
"@clerk/shared": "2.9.0",
"@clerk/types": "4.25.0",
"cookies": "0.8.0"
"cookies": "0.8.0",
"fastify-plugin": "^5.0.1"
},
"devDependencies": {
"@clerk/eslint-config-custom": "*",
"@types/node": "^18.19.33",
"@types/node": "^20.14.8",
"fastify": "^5.0.0",
"tsup": "*",
"typescript": "*"
},
"peerDependencies": {
"fastify": ">=4",
"fastify-plugin": "^4.5.0"
"fastify": ">=5"
},
"engines": {
"node": ">=18.17.0"
"node": ">=20"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 1 addition & 2 deletions packages/fastify/src/clerkPlugin.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,12 @@ const plugin: FastifyPluginCallback<ClerkFastifyOptions> = (
throw new Error(`Unsupported hookName: ${hookName}`);
}

// @ts-expect-error unions don't play well with TS overload signatures
instance.addHook(hookName, withClerkMiddleware(opts));

done();
};

export const clerkPlugin = fp(plugin, {
name: '@clerk/fastify',
fastify: '4.x',
fastify: '5.x',
});
5 changes: 4 additions & 1 deletion playground/fastify/.env.sample
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
CLERK_API_KEY=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
PUBLIC_CLERK_SIGN_IN_URL=/sign-in
FRONTEND_API_URL=
33 changes: 14 additions & 19 deletions playground/fastify/README.md
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
## Setup development
# playground-fastify

Execute in root folder:
Use this example app to test `@clerk/fastify`.

```bash
npm i
npm run build && npm run yalc:all
```
## Usage

Execute in current folder:
1. Install dependencies

```bash
touch .env # set PUBLISHABLE_KEY and SECRET_KEY from Clerk Dashboard API keys
npm i
rm -rf node_modules/@clerk
yalc add @clerk/fastify @clerk/backend @clerk/types --pure
```shell
npm install
```

## Getting Started
1. Use [`@clerk/dev-cli`](https://github.com/clerk/javascript/tree/main/packages/dev-cli) to build all repository packages and install the local version into this playground.

First, run the development server:
1. Start the server:

```bash
```shell
npm run start
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Reload changes from packages/\* package
You can visit these routes:

Apply change in packages/\* project folder and run `npm run build`. Then restart Fastify server by killing the current and executing `npm start` and the change should be visible.
- `/`
- `/sign-in`
- `/me` (requires sign-in)
- `/private` (requires sign-in)
27 changes: 13 additions & 14 deletions playground/fastify/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,21 +6,20 @@
"start": "ts-node ./src/server.ts"
},
"dependencies": {
"@clerk/backend": "file:.yalc/@clerk/backend",
"@clerk/fastify": "file:.yalc/@clerk/fastify",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
Comment on lines -9 to -12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we retain yalc usage here for the playground?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because when you use clerk-dev-cli or secco it gets in the way. If we want to dogfood the dev CLI we need to remove yalc ;)

"@fastify/view": "^8.0.0",
"dotenv": "^16.0.3",
"ejs": "^3.1.9",
"fastify": "^4.12.0",
"ts-node": "^10.9.1"
"@clerk/backend": "^1.13.6",
"@clerk/fastify": "^1.0.49",
"@clerk/shared": "^2.8.4",
"@clerk/types": "^4.23.0",
"@fastify/view": "^10.0.1",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"fastify": "^5.0.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/ejs": "^3.1.2",
"@types/node": "^18.11.18",
"eslint": "8.24.0",
"tslib": "^2.5.0",
"typescript": "4.8.4"
"@types/ejs": "^3.1.5",
"@types/node": "^20.14.8",
"tslib": "^2.7.0",
"typescript": "5.0.4"
}
}
2 changes: 1 addition & 1 deletion playground/fastify/src/loadEnv.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: ['.env.local', '.env.production', '.env'] });
13 changes: 6 additions & 7 deletions playground/fastify/src/routes/public.ts
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
import type { FastifyInstance } from 'fastify';

export const publicRoutes = async (fastify: FastifyInstance, _opts: any) => {
fastify.get('/public', async (_req, _reply) => {
fastify.get('/', async (_req, _reply) => {
return { hello: 'world' };
});

fastify.get('/home', async (_req, reply) => {
return reply.view('/src/templates/home.ejs', {
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
domain: process.env.CLERK_DOMAIN,
isSatellite: process.env.CLERK_IS_SATELLITE,
signInUrl: process.env.CLERK_SIGN_IN_URL,
fastify.get('/sign-in', async (_req, reply) => {
return reply.viewAsync('/src/templates/sign-in.ejs', {
CLERK_PUBLISHABLE_KEY: process.env.CLERK_PUBLISHABLE_KEY,
PUBLIC_CLERK_SIGN_IN_URL: process.env.PUBLIC_CLERK_SIGN_IN_URL,
FRONTEND_API_URL: process.env.FRONTEND_API_URL,
});
});
};
18 changes: 0 additions & 18 deletions playground/fastify/src/templates/home.ejs

This file was deleted.

24 changes: 24 additions & 0 deletions playground/fastify/src/templates/sign-in.ejs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script
async
crossorigin="anonymous"
data-clerk-publishable-key="<%= CLERK_PUBLISHABLE_KEY %>"
src="<%= FRONTEND_API_URL %>/npm/@clerk/clerk-js@latest/dist/clerk.browser.js"
type="text/javascript"
onLoad="startClerk()"
></script>
</head>
<body>
<script>
window.startClerk = async () => {
await Clerk.load({
signInUrl: "<%= PUBLIC_CLERK_SIGN_IN_URL %>",
});
Clerk.openSignIn();
}
</script>
</body>
</html>