-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fastify)!: Support Fastify v5 (#4270)
- Loading branch information
Showing
14 changed files
with
1,591 additions
and
2,977 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
CLERK_API_KEY= | ||
CLERK_PUBLISHABLE_KEY= | ||
CLERK_SECRET_KEY= | ||
PUBLIC_CLERK_SIGN_IN_URL=/sign-in | ||
FRONTEND_API_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
dotenv.config({ path: ['.env.local', '.env.production', '.env'] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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, | ||
}); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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> |