⬆️ Bump vitest from 2.1.1 to 2.1.9 (#1548)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Luke Vella <me@lukevella.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2025-02-08 14:43:15 +07:00 committed by GitHub
parent 480f1a03d1
commit ffafcbdb43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 729 additions and 738 deletions

View file

@ -1,97 +1,47 @@
import languages from "@rallly/languages";
import { withPostHog } from "@rallly/posthog/next/middleware";
import { NextResponse } from "next/server";
import withAuth from "next-auth/middleware";
import NextAuth from "next-auth";
import { getLocaleFromHeader } from "@/app/guest";
import { isSelfHosted } from "@/utils/constants";
import { nextAuthConfig } from "@/next-auth.config";
const { auth } = NextAuth(nextAuthConfig);
const supportedLocales = Object.keys(languages);
const publicRoutes = [
"/login",
"/register",
"/invite/",
"/poll/",
"/auth/login",
];
export default auth(async (req) => {
const { nextUrl } = req;
const newUrl = nextUrl.clone();
if (process.env.QUICK_CREATE_ENABLED === "true") {
publicRoutes.push("/quick-create", "/new");
}
const isLoggedIn = req.auth?.user?.email;
export const middleware = withAuth(
async function middleware(req) {
const { nextUrl } = req;
const newUrl = nextUrl.clone();
// if the user is already logged in, don't let them access the login page
if (/^\/(login)/.test(newUrl.pathname) && isLoggedIn) {
newUrl.pathname = "/";
return NextResponse.redirect(newUrl);
}
const isLoggedIn = req.nextauth.token?.email;
// set x-pathname header to the pathname
// Check if locale is specified in cookie
let locale = req.auth?.user?.locale;
if (locale && supportedLocales.includes(locale)) {
newUrl.pathname = `/${locale}${newUrl.pathname}`;
} else {
// Check if locale is specified in header
locale = await getLocaleFromHeader(req);
// if the user is already logged in, don't let them access the login page
if (/^\/(login)/.test(newUrl.pathname) && isLoggedIn) {
newUrl.pathname = "/";
return NextResponse.redirect(newUrl);
}
newUrl.pathname = `/${locale}${newUrl.pathname}`;
}
// if the user is not logged in and the page is not public, redirect to login
if (
!isLoggedIn &&
!publicRoutes.some((route) => newUrl.pathname.startsWith(route))
) {
if (newUrl.pathname !== "/") {
newUrl.searchParams.set("callbackUrl", newUrl.pathname);
}
newUrl.pathname = "/login";
return NextResponse.redirect(newUrl);
}
const res = NextResponse.rewrite(newUrl);
res.headers.set("x-pathname", newUrl.pathname);
// Check if locale is specified in cookie
let locale = req.nextauth.token?.locale;
if (locale && supportedLocales.includes(locale)) {
newUrl.pathname = `/${locale}${newUrl.pathname}`;
} else {
// Check if locale is specified in header
locale = await getLocaleFromHeader(req);
if (req.auth?.user?.id) {
await withPostHog(res, { distinctID: req.auth.user.id });
}
newUrl.pathname = `/${locale}${newUrl.pathname}`;
}
const res = NextResponse.rewrite(newUrl);
res.headers.set("x-pathname", newUrl.pathname);
if (req.nextauth.token) {
await withPostHog(res, { distinctID: req.nextauth.token.sub });
}
return res;
},
{
secret: process.env.SECRET_PASSWORD,
callbacks: {
authorized: ({ token, req }) => {
const nextUrl = req.nextUrl;
const isGuest = !token?.email;
if (
isSelfHosted &&
isGuest &&
!(
nextUrl.pathname.startsWith("/invite") ||
nextUrl.pathname.startsWith("/login") ||
nextUrl.pathname.startsWith("/register") ||
nextUrl.pathname.startsWith("/auth") ||
nextUrl.pathname.startsWith("/p/")
)
) {
// limit which pages guests can access for self-hosted instances
return false;
}
return true;
},
},
},
);
return res;
});
export const config = {
matcher: ["/((?!api|_next/static|_next/image|static|.*\\.).*)"],