middleware
middleware copied to clipboard
Clerk getAuth inside the app.post
Should something like this work?
app.post(
"/strategies",
async (c) => {
const auth = getAuth(c);
I'm getting empty auth
object
auth {
sessionClaims: null,
sessionId: null,
session: null,
userId: null,
user: null,
actor: null,
orgId: null,
orgRole: null,
orgSlug: null,
organization: null,
getToken: [Function: getToken],
debug: [Function (anonymous)]
}
Same user session returns properly filled auth object when running the code bellow with GET.
app.get(
"/",
async (c) => {
const auth = getAuth(c);
Should getAuth work in POST block or I'm doing something wrong?
I would check two things:
- that the middleware is running for
/
- that the clerk SDK is loaded on the frontend
const clerk = new Clerk(clerkPubKey);
await clerk.load();
The clerk token expires after 60 seconds so you need the JS client present to refresh the token which then set the client side cookie required for auth on the backend