Organization not found. Please contact the invite sender.
+
+
+
+
+
+
This organization wasn't found. Please contact your organization owner.
+
)
}
return (
-
You have been invited to org {orgName.name}
diff --git a/packages/web/src/app/settings/page.tsx b/packages/web/src/app/settings/page.tsx
index acd808b7..7c1b4036 100644
--- a/packages/web/src/app/settings/page.tsx
+++ b/packages/web/src/app/settings/page.tsx
@@ -1,4 +1,3 @@
-import { Header } from "../components/header";
import { auth } from "@/auth";
import { getUser } from "@/data/user";
import { prisma } from "@/prisma";
diff --git a/packages/web/src/auth.ts b/packages/web/src/auth.ts
index f8cf2f43..003c4fe6 100644
--- a/packages/web/src/auth.ts
+++ b/packages/web/src/auth.ts
@@ -111,3 +111,13 @@ export const getCurrentUserOrg = async () => {
return orgId;
}
+
+export const doesUserHaveOrg = async (userId: string) => {
+ const orgs = await prisma.userToOrg.findMany({
+ where: {
+ userId,
+ },
+ });
+
+ return orgs.length > 0;
+}
diff --git a/packages/web/src/middleware.ts b/packages/web/src/middleware.ts
index 97ba638d..bc6c77f7 100644
--- a/packages/web/src/middleware.ts
+++ b/packages/web/src/middleware.ts
@@ -23,10 +23,22 @@ const apiMiddleware = (req: NextAuthRequest) => {
}
const defaultMiddleware = (req: NextAuthRequest) => {
+ // We're not able to check if the user doesn't belong to any orgs in the middleware, since we cannot call prisma. As a result, we do this check
+ // in the root layout. However, there are certain endpoints (ex. login, redeem, onboard) that we want the user to be able to hit even if they don't
+ // belong to an org. It seems like the easiest way to do this is to check for these paths here and pass in a flag to the root layout using the headers
+ // https://github.com/vercel/next.js/discussions/43657#discussioncomment-5981981
+ const bypassOrgCheck = req.nextUrl.pathname === "/login" || req.nextUrl.pathname === "/redeem" || req.nextUrl.pathname.includes("onboard");
+ const requestheaders = new Headers(req.headers);
+ requestheaders.set("x-bypass-org-check", bypassOrgCheck.toString());
+
// if we're trying to redeem an invite while not authed we continue to the redeem page so
// that we can pipe the invite_id to the login page
if (!req.auth && req.nextUrl.pathname === "/redeem") {
- return NextResponse.next();
+ return NextResponse.next({
+ request: {
+ headers: requestheaders,
+ }
+ });
}
if (!req.auth && req.nextUrl.pathname !== "/login") {
@@ -37,7 +49,11 @@ const defaultMiddleware = (req: NextAuthRequest) => {
return NextResponse.redirect(newUrl);
}
- return NextResponse.next();
+ return NextResponse.next({
+ request: {
+ headers: requestheaders,
+ }
+ });
}
export default auth(async (req) => {