-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d808dc
commit 13fd927
Showing
6 changed files
with
174 additions
and
273 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,83 @@ | ||
<Properties> | ||
- `secretKey` (required) | ||
- `string` | ||
|
||
The Clerk Secret Key from the [**API keys**](https://dashboard.clerk.com/last-active?path=api-keys) page in the Clerk Dashboard. | ||
|
||
--- | ||
|
||
- `jwtKey?` | ||
- `string` | ||
|
||
The PEM public key from the **[**API keys**](https://dashboard.clerk.com/last-active?path=api-keys) page -> Show JWT public key -> PEM Public Key** section in the Clerk Dashboard. For more information, refer to [Manual JWT verification](/docs/backend-requests/handling/manual-jwt). | ||
|
||
--- | ||
|
||
- `publishableKey?` | ||
- `string` | ||
|
||
The Clerk Publishable Key from the [**API keys**](https://dashboard.clerk.com/last-active?path=api-keys) page in the Clerk Dashboard. | ||
|
||
--- | ||
|
||
- `domain?` | ||
- `string` | ||
|
||
The domain of a [satellite application](/docs/advanced-usage/satellite-domains) in a multi-domain setup. | ||
|
||
--- | ||
|
||
- `isSatellite?` | ||
- `boolean` | ||
|
||
Whether the instance is a satellite domain in a multi-domain setup. Defaults to `false`. | ||
|
||
--- | ||
|
||
- `proxyUrl?` | ||
- `string` | ||
|
||
The proxy URL from a multi-domain setup. | ||
|
||
--- | ||
|
||
- `sdkMetadata?` | ||
- `{ name: string, version: string }` | ||
|
||
Metadata about the SDK. | ||
|
||
--- | ||
|
||
- `telemetry?` | ||
- `{ disabled: boolean, debug: boolean }` | ||
|
||
[Telemetry](/docs/telemetry) configuration. | ||
|
||
--- | ||
|
||
- `userAgent?` | ||
- `string` | ||
|
||
The User-Agent request header passed to the Clerk API. | ||
|
||
--- | ||
|
||
- `apiUrl?` | ||
- `string` | ||
|
||
The [Clerk Backend API](/docs/reference/backend-api){{ target: '_blank' }} endpoint. Defaults to `'https://api.clerk.com'`. | ||
|
||
--- | ||
|
||
- `apiVersion?` | ||
- `string` | ||
|
||
The version passed to the Clerk API. Defaults to `'v1'`. | ||
|
||
--- | ||
|
||
- `audience?` | ||
- `string | string[]` | ||
|
||
A string or list of [audiences](https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3). | ||
</Properties> |
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,48 @@ | ||
The following example uses `getAuth()` to protect a route and load the user's data. If the user is authenticated, their `userId` is passed to [`clerkClient.users.getUser()`](/docs/references/backend/user/get-user){{ target: '_blank' }} to get the current user's [`User`](/docs/references/javascript/user/user){{ target: '_blank' }} object. If not authenticated, the request is rejected with a `403` status code. | ||
|
||
```ts | ||
// dotenv must be imported before @clerk/fastify | ||
import 'dotenv/config' | ||
import Fastify from 'fastify' | ||
import { clerkClient, clerkPlugin, getAuth } from '@clerk/fastify' | ||
|
||
const fastify = Fastify({ logger: true }) | ||
|
||
fastify.register(clerkPlugin) | ||
|
||
// Use `getAuth()` to protect this route | ||
fastify.get('/protected', async (request, reply) => { | ||
try { | ||
// Use `getAuth()` to get the user's ID | ||
const { userId } = getAuth(request) | ||
|
||
// If user isn't authenticated, return a 403 error | ||
if (!userId) { | ||
return reply.code(403).send({ error: 'Unauthorized request' }) | ||
} | ||
|
||
// Use `clerkClient` to access Clerk's Backend SDK methods | ||
// and get the user's User object | ||
const user = userId ? await clerkClient.users.getUser(userId) : null | ||
|
||
return reply.send({ | ||
message: 'User retrieved successfully', | ||
user, | ||
}) | ||
} catch (error) { | ||
fastify.log.error(error) | ||
return reply.code(500).send({ error: 'Failed to retrieve user' }) | ||
} | ||
}) | ||
|
||
const start = async () => { | ||
try { | ||
await fastify.listen({ port: 8080 }) | ||
} catch (error) { | ||
fastify.log.error(error) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
start() | ||
``` |
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
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
Oops, something went wrong.