@@ -38,6 +51,7 @@ export default function LoginForm() {
setEmail(evt.target.value)}
@@ -50,6 +64,7 @@ export default function LoginForm() {
-
>
);
diff --git a/core/app/api/member/route.ts b/core/app/api/member/route.ts
new file mode 100644
index 0000000000..5449429b54
--- /dev/null
+++ b/core/app/api/member/route.ts
@@ -0,0 +1,28 @@
+import { NextRequest, NextResponse } from "next/server";
+
+import prisma from "prisma/db";
+import { handleErrors } from "~/lib/server";
+
+export async function GET(req: NextRequest) {
+ return await handleErrors(async () => {
+ const email = req.nextUrl.searchParams.get("email");
+ let user;
+ if (email) {
+ try {
+ user = await prisma.user.findUnique({
+ where: { email },
+ });
+ } catch {
+ throw new Error("No user found");
+ }
+
+ const member = await prisma.member.findFirst({
+ where: { userId: user.id },
+ include: { community: true },
+ });
+ return NextResponse.json({ member, status: 200 });
+ } else {
+ throw new Error("No email provided");
+ }
+ });
+}
diff --git a/core/app/api/user/route.ts b/core/app/api/user/route.ts
index 75cfa99c09..629b339bfa 100644
--- a/core/app/api/user/route.ts
+++ b/core/app/api/user/route.ts
@@ -80,7 +80,7 @@ export async function POST(req: NextRequest) {
// });
return NextResponse.json({ message: "Existing account claimed" }, { status: 200 });
} else {
- const newUser = await prisma.user.create({
+ await prisma.user.create({
data: {
supabaseId: data.user.id,
slug: `${slugifyString(firstName)}${
diff --git a/core/app/c/[communitySlug]/LoginSwitcher.tsx b/core/app/c/[communitySlug]/LoginSwitcher.tsx
index addc3716f5..907b771193 100644
--- a/core/app/c/[communitySlug]/LoginSwitcher.tsx
+++ b/core/app/c/[communitySlug]/LoginSwitcher.tsx
@@ -1,6 +1,6 @@
import { getLoginData } from "~/lib/auth/loginData";
import { Avatar, AvatarFallback, AvatarImage } from "ui";
-import LogoutButton from "./LogoutButton";
+import LogoutButton from "../../components/LogoutButton";
import Link from "next/link";
export default async function LoginSwitcher() {
diff --git a/core/app/c/[communitySlug]/layout.tsx b/core/app/c/[communitySlug]/layout.tsx
index 16aa6da28b..c5a86e807b 100644
--- a/core/app/c/[communitySlug]/layout.tsx
+++ b/core/app/c/[communitySlug]/layout.tsx
@@ -31,6 +31,13 @@ export default async function MainLayout({ children, params }: Props) {
if (!community) {
return null;
}
+ const member = await prisma.member.findFirst({
+ where: { userId: loginData.id, communityId: community.id },
+ });
+ if (!member) {
+ redirect("/settings");
+ }
+
const availableCommunities = await getAvailableCommunities(loginData);
return (
diff --git a/core/app/c/[communitySlug]/page.tsx b/core/app/c/[communitySlug]/page.tsx
index 0aa784faad..873a358fba 100644
--- a/core/app/c/[communitySlug]/page.tsx
+++ b/core/app/c/[communitySlug]/page.tsx
@@ -1,6 +1,3 @@
-import { redirect } from "next/navigation";
-import { getLoginData } from "~/lib/auth/loginData";
-
export default async function Page() {
return (
<>
diff --git a/core/app/c/[communitySlug]/pubs/page.tsx b/core/app/c/[communitySlug]/pubs/page.tsx
index a90c0bb34c..f6b4f36fdc 100644
--- a/core/app/c/[communitySlug]/pubs/page.tsx
+++ b/core/app/c/[communitySlug]/pubs/page.tsx
@@ -4,7 +4,6 @@ import PubList from "./PubList";
import PubHeader from "./PubHeader";
import { createToken } from "~/lib/server/token";
import { pubInclude, stageInclude } from "~/lib/types";
-import { redirect } from "next/navigation";
import { expect } from "utils";
const getCommunityPubs = async (communitySlug: string) => {
diff --git a/core/app/c/[communitySlug]/LogoutButton.tsx b/core/app/components/LogoutButton.tsx
similarity index 72%
rename from core/app/c/[communitySlug]/LogoutButton.tsx
rename to core/app/components/LogoutButton.tsx
index 19660cb01d..550a44292e 100644
--- a/core/app/c/[communitySlug]/LogoutButton.tsx
+++ b/core/app/components/LogoutButton.tsx
@@ -1,11 +1,15 @@
"use client";
import { supabase } from "~/lib/supabase";
import { Button } from "ui";
+import { useRouter } from "next/navigation";
export default function LogoutButton() {
+ const router = useRouter();
+
const handleSignout = async () => {
await supabase.auth.signOut();
- window.location.href = "/";
+ router.refresh();
+ router.push("/");
};
return (
diff --git a/core/app/globals.css b/core/app/globals.css
index aaf1c3f2c9..8822420762 100644
--- a/core/app/globals.css
+++ b/core/app/globals.css
@@ -3,4 +3,4 @@
@tailwind utilities;
/* Not clear why we need this here if we
-also import ui/styles which includes it */
\ No newline at end of file
+also import ui/styles which includes it */
diff --git a/core/app/layout.tsx b/core/app/layout.tsx
index f0e96f8589..677e6160c7 100644
--- a/core/app/layout.tsx
+++ b/core/app/layout.tsx
@@ -1,7 +1,7 @@
+import { Toaster } from "ui";
import "ui/styles.css";
-import "./globals.css";
import InitClient from "./InitClient";
-import { Toaster } from "ui";
+import "./globals.css";
export const metadata = {
title: "PubPub v7 Mockup Demo",
diff --git a/core/app/page.tsx b/core/app/page.tsx
index 3fc1d5b254..e9e87d0de9 100644
--- a/core/app/page.tsx
+++ b/core/app/page.tsx
@@ -1,28 +1,30 @@
-import prisma from "~/prisma/db";
import { redirect } from "next/navigation";
import { getLoginData } from "~/lib/auth/loginData";
+import prisma from "~/prisma/db";
export default async function Page() {
const loginData = await getLoginData();
+ // if user and no commuhnmitiy, redirect to settings
if (loginData) {
- /* If we have a logged in user navigating to `/`, check */
- /* if they are a member of any community, and if so, */
- /* redirect them to that community by default. We could */
- /* eventually have a query param override, but this */
- /* assumes that logged in users landing on pubpub.org */
- /* want to go to their dashboard a la github or twitter */
- /* TODO: Does not select for member-group access yet */
- const community = await prisma.community.findFirst({
- where: { members: { some: { userId: loginData.id } } },
- select: { slug: true },
- });
- if (community) {
- redirect(`/c/${community.slug}`);
+ let user;
+ try {
+ user = await prisma.user.findUnique({
+ where: { email: loginData.email },
+ });
+
+ const member = await prisma.member.findFirst({
+ where: { userId: user.id },
+ include: { community: true },
+ });
+
+ if (member) {
+ redirect(`/c/${member.community.slug}`);
+ } else {
+ redirect("/settings");
+ }
+ } catch {
+ throw new Error("Not able to redirect user");
}
}
- return (
- <>
- Home
- >
- );
+ return <>Home...>;
}
diff --git a/core/lib/auth/loginData.ts b/core/lib/auth/loginData.ts
index f39c5a5f78..3c92bec528 100644
--- a/core/lib/auth/loginData.ts
+++ b/core/lib/auth/loginData.ts
@@ -53,8 +53,8 @@ export const getLoginData = cache(async () => {
create: {
communityId,
canAdmin,
- }
- }
+ },
+ },
},
});
}
diff --git a/core/public/logos/icon.svg b/core/public/logos/icon.svg
index 8a259b949d..e9c28b396c 100644
--- a/core/public/logos/icon.svg
+++ b/core/public/logos/icon.svg
@@ -5,4 +5,4 @@
\ No newline at end of file
+-->
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index cb11a53367..22149443f1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -40,7 +40,7 @@ importers:
version: 0.1.11(prettier@2.8.8)
turbo:
specifier: latest
- version: 1.10.16
+ version: 1.10.15
core:
dependencies:
@@ -9147,64 +9147,64 @@ packages:
yargs: 17.7.2
dev: true
- /turbo-darwin-64@1.10.16:
- resolution: {integrity: sha512-+Jk91FNcp9e9NCLYlvDDlp2HwEDp14F9N42IoW3dmHI5ZkGSXzalbhVcrx3DOox3QfiNUHxzWg4d7CnVNCuuMg==}
+ /turbo-darwin-64@1.10.15:
+ resolution: {integrity: sha512-Sik5uogjkRTe1XVP9TC2GryEMOJCaKE2pM/O9uLn4koQDnWKGcLQv+mDU+H+9DXvKLnJnKCD18OVRkwK5tdpoA==}
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
- /turbo-darwin-arm64@1.10.16:
- resolution: {integrity: sha512-jqGpFZipIivkRp/i+jnL8npX0VssE6IAVNKtu573LXtssZdV/S+fRGYA16tI46xJGxSAivrZ/IcgZrV6Jk80bw==}
+ /turbo-darwin-arm64@1.10.15:
+ resolution: {integrity: sha512-xwqyFDYUcl2xwXyGPmHkmgnNm4Cy0oNzMpMOBGRr5x64SErS7QQLR4VHb0ubiR+VAb8M+ECPklU6vD1Gm+wekg==}
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
- /turbo-linux-64@1.10.16:
- resolution: {integrity: sha512-PpqEZHwLoizQ6sTUvmImcRmACyRk9EWLXGlqceogPZsJ1jTRK3sfcF9fC2W56zkSIzuLEP07k5kl+ZxJd8JMcg==}
+ /turbo-linux-64@1.10.15:
+ resolution: {integrity: sha512-dM07SiO3RMAJ09Z+uB2LNUSkPp3I1IMF8goH5eLj+d8Kkwoxd/+qbUZOj9RvInyxU/IhlnO9w3PGd3Hp14m/nA==}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
- /turbo-linux-arm64@1.10.16:
- resolution: {integrity: sha512-TMjFYz8to1QE0fKVXCIvG/4giyfnmqcQIwjdNfJvKjBxn22PpbjeuFuQ5kNXshUTRaTJihFbuuCcb5OYFNx4uw==}
+ /turbo-linux-arm64@1.10.15:
+ resolution: {integrity: sha512-MkzKLkKYKyrz4lwfjNXH8aTny5+Hmiu4SFBZbx+5C0vOlyp6fV5jZANDBvLXWiDDL4DSEAuCEK/2cmN6FVH1ow==}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
- /turbo-windows-64@1.10.16:
- resolution: {integrity: sha512-+jsf68krs0N66FfC4/zZvioUap/Tq3sPFumnMV+EBo8jFdqs4yehd6+MxIwYTjSQLIcpH8KoNMB0gQYhJRLZzw==}
+ /turbo-windows-64@1.10.15:
+ resolution: {integrity: sha512-3TdVU+WEH9ThvQGwV3ieX/XHebtYNHv9HARHauPwmVj3kakoALkpGxLclkHFBLdLKkqDvmHmXtcsfs6cXXRHJg==}
cpu: [x64]
os: [win32]
requiresBuild: true
dev: true
optional: true
- /turbo-windows-arm64@1.10.16:
- resolution: {integrity: sha512-sKm3hcMM1bl0B3PLG4ifidicOGfoJmOEacM5JtgBkYM48ncMHjkHfFY7HrJHZHUnXM4l05RQTpLFoOl/uIo2HQ==}
+ /turbo-windows-arm64@1.10.15:
+ resolution: {integrity: sha512-l+7UOBCbfadvPMYsX08hyLD+UIoAkg6ojfH+E8aud3gcA1padpjCJTh9gMpm3QdMbKwZteT5uUM+wyi6Rbbyww==}
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: true
optional: true
- /turbo@1.10.16:
- resolution: {integrity: sha512-2CEaK4FIuSZiP83iFa9GqMTQhroW2QryckVqUydmg4tx78baftTOS0O+oDAhvo9r9Nit4xUEtC1RAHoqs6ZEtg==}
+ /turbo@1.10.15:
+ resolution: {integrity: sha512-mKKkqsuDAQy1wCCIjCdG+jOCwUflhckDMSRoeBPcIL/CnCl7c5yRDFe7SyaXloUUkt4tUR0rvNIhVCcT7YeQpg==}
hasBin: true
optionalDependencies:
- turbo-darwin-64: 1.10.16
- turbo-darwin-arm64: 1.10.16
- turbo-linux-64: 1.10.16
- turbo-linux-arm64: 1.10.16
- turbo-windows-64: 1.10.16
- turbo-windows-arm64: 1.10.16
+ turbo-darwin-64: 1.10.15
+ turbo-darwin-arm64: 1.10.15
+ turbo-linux-64: 1.10.15
+ turbo-linux-arm64: 1.10.15
+ turbo-windows-64: 1.10.15
+ turbo-windows-arm64: 1.10.15
dev: true
/type-fest@0.13.1: