aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/app
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-02-21 16:11:35 -0700
committerDhravya <[email protected]>2024-02-21 16:11:35 -0700
commitcdceb1bc87dc2d5ef42a7f172ea5dc2263c5c526 (patch)
treee0234f7fff63b312f18c945bed37a430d1e68755 /apps/web/src/app
downloadsupermemory-cdceb1bc87dc2d5ef42a7f172ea5dc2263c5c526.tar.xz
supermemory-cdceb1bc87dc2d5ef42a7f172ea5dc2263c5c526.zip
initialised monorepo with auth and extension communication
Diffstat (limited to 'apps/web/src/app')
-rw-r--r--apps/web/src/app/account/client.tsx20
-rw-r--r--apps/web/src/app/account/page.tsx10
-rw-r--r--apps/web/src/app/api/auth/[...nextauth]/route.ts7
-rw-r--r--apps/web/src/app/api/store/route.ts21
-rw-r--r--apps/web/src/app/layout.tsx26
-rw-r--r--apps/web/src/app/page.tsx7
6 files changed, 91 insertions, 0 deletions
diff --git a/apps/web/src/app/account/client.tsx b/apps/web/src/app/account/client.tsx
new file mode 100644
index 00000000..f05d0a3c
--- /dev/null
+++ b/apps/web/src/app/account/client.tsx
@@ -0,0 +1,20 @@
+'use client'
+
+import { useEffect } from "react"
+
+function MessagePoster({ jwt }: { jwt: string }) {
+
+ useEffect(() => {
+ if (typeof window === 'undefined') return
+
+ // post every 1000ms
+ setInterval(() => {
+ window.postMessage({ jwt }, '*')
+ }, 1000)
+ }
+ , [jwt])
+
+ return null
+}
+
+export default MessagePoster \ No newline at end of file
diff --git a/apps/web/src/app/account/page.tsx b/apps/web/src/app/account/page.tsx
new file mode 100644
index 00000000..4503f416
--- /dev/null
+++ b/apps/web/src/app/account/page.tsx
@@ -0,0 +1,10 @@
+import { cookies } from 'next/headers';
+import MessagePoster from './client';
+
+async function Page() {
+ const token = cookies().get('next-auth.session-token')?.value
+
+ return <MessagePoster jwt={token!} />
+}
+
+export default Page \ No newline at end of file
diff --git a/apps/web/src/app/api/auth/[...nextauth]/route.ts b/apps/web/src/app/api/auth/[...nextauth]/route.ts
new file mode 100644
index 00000000..1570f886
--- /dev/null
+++ b/apps/web/src/app/api/auth/[...nextauth]/route.ts
@@ -0,0 +1,7 @@
+import NextAuth from "next-auth";
+
+import { authOptions } from "@/server/auth";
+
+// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+const handler = NextAuth(authOptions);
+export { handler as GET, handler as POST };
diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts
new file mode 100644
index 00000000..5c7e76d5
--- /dev/null
+++ b/apps/web/src/app/api/store/route.ts
@@ -0,0 +1,21 @@
+import { db } from "@/server/db";
+import { eq } from "drizzle-orm";
+import { sessions, users } from "@/server/db/schema";
+import { type NextRequest, NextResponse } from "next/server";
+
+export async function GET(req: NextRequest) {
+ try {
+ const token = req.cookies.get("next-auth.session-token")?.value ?? req.headers.get("Authorization")?.replace("Bearer ", "");
+
+ const session = await db.select().from(sessions).where(eq(sessions.sessionToken, token!))
+ .leftJoin(users, eq(sessions.userId, users.id))
+
+ if (!session || session.length === 0) {
+ return NextResponse.json({ message: "Invalid Key, session not found." }, { status: 404 });
+ }
+
+ return NextResponse.json({ message: "OK", data: session[0] }, { status: 200 });
+ } catch (error) {
+ return NextResponse.json({ message: "Error", error }, { status: 500 });
+ }
+} \ No newline at end of file
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
new file mode 100644
index 00000000..70f9df5d
--- /dev/null
+++ b/apps/web/src/app/layout.tsx
@@ -0,0 +1,26 @@
+import "@/styles/globals.css";
+
+import { Inter } from "next/font/google";
+
+const inter = Inter({
+ subsets: ["latin"],
+ variable: "--font-sans",
+});
+
+export const metadata = {
+ title: "Create T3 App",
+ description: "Generated by create-t3-app",
+ icons: [{ rel: "icon", url: "/favicon.ico" }],
+};
+
+export default function RootLayout({
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ return (
+ <html lang="en">
+ <body className={`font-sans ${inter.variable}`}>{children}</body>
+ </html>
+ );
+}
diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx
new file mode 100644
index 00000000..ba5030c7
--- /dev/null
+++ b/apps/web/src/app/page.tsx
@@ -0,0 +1,7 @@
+import Link from "next/link";
+
+export default function HomePage() {
+ return (
+ <main>hi</main>
+ );
+}