fix(jitsi): read session from stalwart auth context, not basic-auth session cookie
PR Verify / verify (pull_request) Successful in 1m0s

In OAuth/OIDC-only mode the webmail never sets the basic-auth session cookie
(sessionCookieName(0)); the login stores auth in the jmap_stalwart_ctx cookie
via /api/auth/stalwart-context. The route was 401-ing for every real user.
This commit is contained in:
Bernd Rodler
2026-08-31 01:24:54 +02:00
parent 2116798281
commit 150adf5a27
+7 -11
View File
@@ -1,8 +1,6 @@
import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers';
import { createHmac } from 'node:crypto';
import { decryptSession } from '@/lib/auth/crypto';
import { sessionCookieName } from '@/lib/auth/session-cookie';
import { readStalwartAuthContext } from '@/lib/stalwart/auth-context';
import { logger } from '@/lib/logger';
const JITSI_URL = (process.env.JITSI_URL || 'https://meet.src-advisory.com').replace(/\/+$/, '');
@@ -23,16 +21,14 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: 'Jitsi is not configured' }, { status: 503 });
}
const cookieStore = await cookies();
const sessionToken = cookieStore.get(sessionCookieName(0))?.value;
if (!sessionToken) {
// In OAuth/OIDC mode the session lives in the `jmap_stalwart_ctx` cookie
// (written by /api/auth/stalwart-context), not the basic-auth session
// cookie. The username there is the primary identity email.
const ctx = await readStalwartAuthContext(0);
const email = ctx?.username;
if (!email) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const session = decryptSession(sessionToken);
if (!session) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const email = session.username;
const body = await request.json().catch(() => ({}));
const room = typeof body.room === 'string' ? body.room.trim() : '';