♻️ Make user session optional (#1515)

This commit is contained in:
Luke Vella 2025-01-27 13:02:34 +00:00 committed by GitHub
parent f6a0bca4f8
commit 58d5c42a6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 343 additions and 549 deletions

View file

@ -3,7 +3,7 @@ import { withPostHog } from "@rallly/posthog/next/middleware";
import { NextResponse } from "next/server";
import withAuth from "next-auth/middleware";
import { getLocaleFromHeader, initGuest } from "@/app/guest";
import { getLocaleFromHeader } from "@/app/guest";
import { isSelfHosted } from "@/utils/constants";
const supportedLocales = Object.keys(languages);
@ -55,10 +55,9 @@ export const middleware = withAuth(
const res = NextResponse.rewrite(newUrl);
res.headers.set("x-pathname", newUrl.pathname);
const jwt = await initGuest(req, res);
if (jwt?.sub) {
await withPostHog(res, { distinctID: jwt.sub });
if (req.nextauth.token) {
await withPostHog(res, { distinctID: req.nextauth.token.sub });
}
return res;