#[SOLVED] Internal Blitz Error: globalThis.__BLITZ_SESSION_COOKIE_PREFIX is not set

1 messages ยท Page 1 of 1 (latest)

frank sinew
#

Has anyone seen this error before? It seems to happen after deployment or when I restart the app on localhost. The fix is to log in. So it seems that I need to refresh the session. Is there a way to fix this as it causes errors on the live application?

Thanks

frank sinew
#

This is still unsolved, I would appreciate some help as I have spend all day today trying to make sense of this but still no luck.

The full error response looks like this

Error: Internal Blitz Error: globalThis.__BLITZ_SESSION_COOKIE_PREFIX is not set
    at prefix (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/index.mjs:52:11)
    at COOKIE_CSRF_TOKEN (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/index.mjs:59:36)
    at eval (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/auth-plugin.mjs:177:84)
    at Generator.next (<anonymous>)
    at eval (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/auth-plugin.mjs:80:61)
    at new Promise (<anonymous>)
    at __async$1 (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/auth-plugin.mjs:64:10)
    at getBlitzContext (webpack-internal:///(rsc)/./node_modules/@blitzjs/auth/dist/chunks/auth-plugin.mjs:172:10)
    at EventPage (webpack-internal:///(rsc)/./src/app/p/[expertIdOrSlug]/[eventType]/[eventId]/page.tsx:50:69)
#

I checked the source code. Calling COOKIE_CSRF_TOKEN() throws this error if globalThis.__BLITZ_SESSION_COOKIE_PREFIX is not set. But this should be set when either AuthServerPlugin() or AuthClientPlugin() is called. This is obviously the case in my app, see my blitz-server.ts for example

import { setupBlitzServer } from "@blitzjs/next";
import { AuthServerPlugin, PrismaStorage, simpleRolesIsAuthorized } from "@blitzjs/auth";
import db from "db";
import { BlitzLogger } from "blitz";
import { RpcServerPlugin } from "@blitzjs/rpc";
import { authConfig } from "./blitz-auth-config";

const logLevel = Number(process.env.BLITZ_LOGGER_MIN_LEVEL ?? "4");

console.log("setupBlitzServer()");
const { api, getBlitzContext, useAuthenticatedBlitzContext, invoke } = setupBlitzServer({
  plugins: [
    AuthServerPlugin({
      ...authConfig,
      storage: PrismaStorage(db),
      isAuthorized: simpleRolesIsAuthorized
    }),
    RpcServerPlugin({})
  ],
  logger: BlitzLogger({ minLevel: logLevel })
});

export { api, getBlitzContext, useAuthenticatedBlitzContext, invoke };
#

So on each page where I call await getBlitzContext(); I get this error when I redeploy the app as well as when I restart blitz dev on localhost

#

I something not getting initialized properly?

#

@native hedge I would be eternally grateful if you could read through my issue description ๐Ÿ‘†๐Ÿผ Thank you so much ๐Ÿ™๐Ÿผ ๐Ÿ™๐Ÿผ ๐Ÿ™๐Ÿผ

native hedge
#

Reading through it now @frank sinew

#

The getBlitzContext how are you importing it?

#

Is there any blitz auth function you are importing directly from the package and not from the blitz client / sever files?

frank sinew
#

Yes, I am importing it like this import { getBlitzContext } from "@blitzjs/auth";

#

Ahh, I know what you mean, should I import it from the blith-server.ts?

frank sinew
#

Makes total sense, I didn't see that you can import it from two different locations. Seems to have fixed the issue. Thanks a lot ๐Ÿ™๐Ÿผ ๐Ÿ™๐Ÿผ ๐Ÿ™๐Ÿผ

#

[SOLVED] Internal Blitz Error: globalThis.__BLITZ_SESSION_COOKIE_PREFIX is not set

native hedge
#

Yeah will see if I can remove that export from the package to reduce this confusion.