Locals
Through Astro locals
, Clerk's Auth
and current User
objects can be accessed between middlewares and pages. These locals are injected when you install the provided middleware.
The following guide provides examples of using the auth()
local to validate an authenticated user and the currentUser()
local to access the Backend API User
object for the authenticated user.
Protect your pages
You can use the auth()
local to protect your pages and forms. It will return the current user's ID if they are signed in, or null
if they are not. For more information on auth()
, see the reference.
Accessing the current user
Current user data is important for data enrichment. You can use the currentUser()
local to fetch the current user's data in your pages.
Under the hood, this local:
- uses the
GET /v1/users/me
endpoint. - counts towards the Backend API Request Rate Limit.
For more information on currentUser()
, see the reference.
Feedback
Last updated on