Endpoints
Clerk provides helpers that allow you to protect your Astro endpoints, fetch the current user, and interact with the Clerk backend API.
Protect your endpoints
If you aren't protecting your endpoints using clerkMiddleware()
, you can use the auth()
local and check for the userId
value, as shown in the following example:
Retrieve data from external sources
Clerk provides integrations with a number of popular databases.
To retrieve a token from a JWT template and fetch data from an external source, use the getToken()
method from the auth()
local, as shown in the following example:
Retrieve the current user
In some cases, you might need the current user in your endpoint. Use the asynchronous currentUser()
local to retrieve the current Backend User
object, as shown in the following example:
Interact with Clerk's Backend API
The JavaScript Backend SDK exposes Clerk's backend API resources and low-level authentication utilities for JavaScript environments.
clerkClient
exposes an instance of the JavaScript Backend SDK for use in server environments. Use this instance to interact with the Clerk backend API, as shown in the following example:
Feedback
Last updated on