[blitz-auth / blitz-rpc] getBlitzContext hardcodes isRsc: true and method: "POST", silently disabling $create/$revoke in Server Actions and crashing RSC page renders
Author: codeCraft-RitikCreated Sep 26, 2026Updated Sep 26, 2026
Labelskind/bugstatus/triage
What is the problem?
getBlitzContext() is the sole context provider for App Router server invocations (globalThis.__BLITZ_GET_RSC_CONTEXT used by invoke(mutation, params)).
It currently hardcodes isRsc = true and method = "POST":
- Silent Failure in Server Actions: In
SessionContextClass,$create(),$revoke(), and$setPublicData()begin with:While React Server Components cannot mutate cookies during rendering, Next.js Server Actions and Route Handlers are explicitly designed to mutate cookies viaif (this._isRsc) { void NotSupportedMessage("$create") return }cookies().set(...). BecauseisRsc = trueis hardcoded, invoking a login or logout mutation inside a Server Action silently no-ops, never creates the database session, never issues cookies, and leaves the user logged out. - False CSRF Failures in RSC Page Views: Because
method: "POST"is hardcoded,getSessiontriggers CSRF protection (enableCsrfProtection = method !== "GET"). When a user navigates to an RSC page via a direct link or external navigation (an HTTP GET request), Blitz treats it as a POST without an anti-CSRF token, throwingCSRFTokenMismatchError()and crashing the page.
Paste all your error logs here:
// When calling auth mutation from Server Action:
Method $create is not yet supported in React Server Components
// When loading RSC page directly:
CSRFTokenMismatchError: Authentication failed: Anti-CSRF token mismatch.
at getSessionKernel (packages/blitz-auth/src/server/auth-sessions.ts:832:13)
at async getSession (packages/blitz-auth/src/server/auth-sessions.ts:250:23)
at async getBlitzContext (packages/blitz-auth/src/server/auth-sessions.ts:299:21)
at async DashboardPage (src/app/dashboard/page.tsx:8:15)Paste all relevant code snippets here:
// packages/blitz-auth/src/server/auth-sessions.ts (lines 289-319)
export async function getBlitzContext(): Promise<Ctx> {
try {
const {headers, cookies} = require("next/headers")
const cookieStore = await cookies()
const headersStore = await headers()
const reqHeader = Object.fromEntries(headersStore)
const csrfToken = cookieStore.get(COOKIE_CSRF_TOKEN())
if (csrfToken) {
reqHeader[HEADER_CSRF] = csrfToken.value
}
const session = await getSession(
{
headers: new Headers(reqHeader),
method: "POST", // BUG: Hardcoded POST triggers CSRF check during GET page renders
} as Request,
null as never,
true, // BUG: Hardcoded isRsc: true disables $create/$revoke in Server Actions
)
const ctx: Ctx = {
session,
}
return ctx
...
}
// packages/blitz-auth/src/server/auth-sessions.ts (lines 486-508)
async $create(publicData: PublicData, privateData?: Record<any, any>) {
if (this._isRsc) {
void NotSupportedMessage("$create")
return // BUG: Silently aborts in Server Actions!
}
...
}
async $revoke() {
if (this._isRsc) {
void NotSupportedMessage("$revoke")
return // BUG: Silently aborts in Server Actions!
}
...
}What are detailed steps to reproduce this?
- In a Blitz App Router project, create a Server Action:
// src/app/actions.ts "use server" import { invoke } from "src/blitz-server" import login from "src/auth/mutations/login" export async function handleLogin(formData: FormData) { await invoke(login, { email: formData.get("email"), password: formData.get("password") }) } - Submit the form.
- Observe terminal output:
Method $create is not yet supported in React Server Components - Inspect the database
Sessiontable: no session was created. - In browser: no session cookies are present; user remains logged out.
- Now visit any page calling
getBlitzContext()via an incognito window: it throwsCSRFTokenMismatchErrorbecausemethod: "POST"is checked on an initial GET navigation.
Run blitz -v and paste the output here:
macOS / Windows / Linux
blitz: 3.0.2 (local)
@blitzjs/auth: 3.0.2 (local)
@blitzjs/next: 3.0.2 (local)
@blitzjs/rpc: 3.0.2 (local)Please include below any other applicable logs and screenshots that show your problem:
Server Action Invocation Flow:
Client Form Submit -> Server Action -> invoke(login) -> getBlitzContext()
│
┌──────────────────┴──────────────────┐
▼ ▼
isRsc = true method = "POST"
│ │
$create() silently aborts CSRF check enforced on GETs
No DB record, No cookies Crashes with CSRFTokenMismatchErrorProposed Fix (Pull Request diff):
--- a/packages/blitz-auth/src/server/auth-sessions.ts
+++ b/packages/blitz-auth/src/server/auth-sessions.ts
@@ -286,22 +286,30 @@ const makeProxyToPublicData = <T extends SessionContextClass>(ctxClass: T): T =>
})
}
-export async function getBlitzContext(): Promise<Ctx> {
+export interface BlitzContextOptions {
+ isRsc?: boolean
+ method?: string
+}
+
+export async function getBlitzContext(options: BlitzContextOptions = {}): Promise<Ctx> {
try {
const {headers, cookies} = require("next/headers")
const cookieStore = await cookies()
const headersStore = await headers()
const reqHeader = Object.fromEntries(headersStore)
const csrfToken = cookieStore.get(COOKIE_CSRF_TOKEN())
if (csrfToken) {
reqHeader[HEADER_CSRF] = csrfToken.value
}
+ const isRsc = options.isRsc ?? true
+ const method = options.method ?? (isRsc ? "GET" : "POST")
+
const session = await getSession(
{
headers: new Headers(reqHeader),
- method: "POST",
+ method,
} as Request,
null as never,
- true,
+ isRsc,
)
const ctx: Ctx = {Source: blitz-js/blitz