mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-21 02:07:23 +02:00
♻️ Make user session optional (#1515)
This commit is contained in:
parent
f6a0bca4f8
commit
58d5c42a6c
31 changed files with 343 additions and 549 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue