Closed jonathanharg closed 1 year ago
Stepped through the lucia auth source code with a debugger. Looks like its a CSRF issue. Line 99 of request.js
this.validateUserPromise = new Promise(async (resolve) => {
try {
const sessionId = this.auth.parseRequestHeaders(this.context.request);
if (!sessionId)
return resolveNullSession(resolve);
const { session, user } = await this.auth.validateSessionUser(sessionId);
this.setSession(session);
return resolve({ session, user });
}
catch {
return resolveNullSession(resolve);
}
});
Here parseRequestHeaders
throws a Lucia error because it fails a CSRF check for some reason (still not sure why). This is then caught without an error message and creates a null session. Disabling CSRF temporarily fixes this issue.
Also on a side note, it seems quite unintuitive that you can call getCookie()
on an AuthRequest and get a null despite there being valid session cookies.
Does req.url
not return the full url (with the protocol and host)? That's likely the issue
Does
req.url
not return the full url (with the protocol and host)? That's likely the issue
It returns just the path, in this case /api/trpc/status.authMutation?batch=1
Should be resolved with #525
I'll add that this fix will be implemented in 1.3.0, which might take a while to come out (like at most 1 week)
Package
@lucia-auth/nextjs
Package version
1.2.1
Describe the bug
I have set up the following context with TRPC which seems to be causing issues (using node middleware).
This is the console output for calling a basic mutation which just prints to console. The request cookie is a valid one, I have checked in the database.
Curiously TRPC queries do seem to work. Here is the output of a TRPC query.
Here is my fairly bog-standard auth middleware.
System info
@lucia-auth/adapter-prisma 1.0.0 next 13.3.0 lucia-auth 1.2.2 trpc 10.20.0 node v19.9.0
Reproduction
No response
Relevant log output
No response
Additional information
No response