mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-19 17:27:26 +02:00
✨ Add setup screen (#1682)
This commit is contained in:
parent
42d0077045
commit
843dfc4a7d
19 changed files with 526 additions and 93 deletions
|
@ -10,30 +10,23 @@ const supportedLocales = Object.keys(languages);
|
|||
export const middleware = withAuth(async (req) => {
|
||||
const { nextUrl } = req;
|
||||
const newUrl = nextUrl.clone();
|
||||
const pathname = newUrl.pathname;
|
||||
|
||||
const isLoggedIn = req.auth?.user?.email;
|
||||
// if the user is already logged in, don't let them access the login page
|
||||
if (
|
||||
/^\/(login)/.test(newUrl.pathname) &&
|
||||
isLoggedIn &&
|
||||
!newUrl.searchParams.get("invalidSession")
|
||||
) {
|
||||
if (/^\/(login)/.test(pathname) && isLoggedIn) {
|
||||
newUrl.pathname = "/";
|
||||
return NextResponse.redirect(newUrl);
|
||||
}
|
||||
|
||||
// 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 = getPreferredLocale(req);
|
||||
newUrl.pathname = `/${locale}${newUrl.pathname}`;
|
||||
const locale = req.auth?.user?.locale || getPreferredLocale(req);
|
||||
if (supportedLocales.includes(locale)) {
|
||||
newUrl.pathname = `/${locale}${pathname}`;
|
||||
}
|
||||
|
||||
const res = NextResponse.rewrite(newUrl);
|
||||
res.headers.set("x-pathname", newUrl.pathname);
|
||||
res.headers.set("x-locale", locale);
|
||||
res.headers.set("x-pathname", pathname);
|
||||
|
||||
if (req.auth?.user?.id) {
|
||||
await withPostHog(res, { distinctID: req.auth.user.id });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue