Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,19 @@ export async function getSessionFromCookie(request?: NextRequest) {
async function getSessionFromHeader(): Promise<Session | undefined> {
const headersList = await headers();
const hasMiddleware = Boolean(headersList.get(middlewareHeaderName));
const skipMiddlewareCheck = process.env.WORKOS_SKIP_MIDDLEWARE_CHECK === 'true';

if (!hasMiddleware) {
if (!hasMiddleware && !skipMiddlewareCheck) {
const url = headersList.get('x-url');
throw new Error(
`You are calling 'withAuth' on ${url ?? 'a route'} that isn't covered by the AuthKit middleware. Make sure it is running on all paths you are calling 'withAuth' from by updating your middleware config in 'middleware.(js|ts)'.`,
);
}

if (!hasMiddleware && skipMiddlewareCheck) {
return getSessionFromCookie();
}

const authHeader = headersList.get(sessionHeaderName);
if (!authHeader) return;

Expand Down