aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src')
-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.ts9
-rw-r--r--apps/web/src/app/api/store/route.ts3
-rw-r--r--apps/web/src/app/layout.tsx16
-rw-r--r--apps/web/src/app/page.tsx9
-rw-r--r--apps/web/src/env.js2
-rw-r--r--apps/web/src/server/auth.ts79
-rw-r--r--apps/web/src/server/db/index.ts8
9 files changed, 44 insertions, 112 deletions
diff --git a/apps/web/src/app/account/client.tsx b/apps/web/src/app/account/client.tsx
deleted file mode 100644
index f05d0a3c..00000000
--- a/apps/web/src/app/account/client.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-'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
deleted file mode 100644
index 4503f416..00000000
--- a/apps/web/src/app/account/page.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-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
index 1570f886..db7d1fb8 100644
--- a/apps/web/src/app/api/auth/[...nextauth]/route.ts
+++ b/apps/web/src/app/api/auth/[...nextauth]/route.ts
@@ -1,7 +1,2 @@
-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 };
+export { GET, POST } from "@/server/auth";
+export const runtime = "edge";
diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts
index 5c7e76d5..0d1c38ff 100644
--- a/apps/web/src/app/api/store/route.ts
+++ b/apps/web/src/app/api/store/route.ts
@@ -3,6 +3,8 @@ import { eq } from "drizzle-orm";
import { sessions, users } from "@/server/db/schema";
import { type NextRequest, NextResponse } from "next/server";
+export const runtime = "edge";
+
export async function GET(req: NextRequest) {
try {
const token = req.cookies.get("next-auth.session-token")?.value ?? req.headers.get("Authorization")?.replace("Bearer ", "");
@@ -13,7 +15,6 @@ export async function GET(req: NextRequest) {
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 });
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index 70f9df5d..9d62d395 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -1,18 +1,20 @@
-import "@/styles/globals.css";
+import '@/styles/globals.css';
-import { Inter } from "next/font/google";
+import { Inter } from 'next/font/google';
const inter = Inter({
- subsets: ["latin"],
- variable: "--font-sans",
+ subsets: ['latin'],
+ variable: '--font-sans',
});
export const metadata = {
- title: "Create T3 App",
- description: "Generated by create-t3-app",
- icons: [{ rel: "icon", url: "/favicon.ico" }],
+ title: 'Create T3 App',
+ description: 'Generated by create-t3-app',
+ icons: [{ rel: 'icon', url: '/favicon.ico' }],
};
+export const runtime = 'edge';
+
export default function RootLayout({
children,
}: {
diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx
index ba5030c7..3b9e44c4 100644
--- a/apps/web/src/app/page.tsx
+++ b/apps/web/src/app/page.tsx
@@ -1,7 +1,12 @@
-import Link from "next/link";
+import { cookies } from 'next/headers';
+import MessagePoster from '../../../anycontext-front/src/app/MessagePoster';
+
+export const runtime = 'edge';
export default function HomePage() {
return (
- <main>hi</main>
+ <main>
+ <MessagePoster jwt={cookies().get('next-auth.session-token')?.value!} />
+ </main>
);
}
diff --git a/apps/web/src/env.js b/apps/web/src/env.js
index 7bc15152..eea6b505 100644
--- a/apps/web/src/env.js
+++ b/apps/web/src/env.js
@@ -28,7 +28,7 @@ export const env = createEnv({
process.env.VERCEL ? z.string() : z.string().url()
),
GOOGLE_CLIENT_ID: z.string(),
- GOOGLE_CLIENT_SECRET: z.string(),
+ GOOGLE_CLIENT_SECRET: z.string()
},
/**
diff --git a/apps/web/src/server/auth.ts b/apps/web/src/server/auth.ts
index cb0a26d9..3b8d749e 100644
--- a/apps/web/src/server/auth.ts
+++ b/apps/web/src/server/auth.ts
@@ -1,74 +1,37 @@
-import { DrizzleAdapter } from "@auth/drizzle-adapter";
-import {
- getServerSession,
- type DefaultSession,
- type NextAuthOptions,
-} from "next-auth";
-import { type Adapter } from "next-auth/adapters";
-import GoogleProvider from "next-auth/providers/google";
-
import { env } from "@/env";
-import { db } from "@/server/db";
-import { createTable } from "@/server/db/schema";
-
-/**
- * Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
- * object and keep type safety.
- *
- * @see https://next-auth.js.org/getting-started/typescript#module-augmentation
- */
-declare module "next-auth" {
- interface Session extends DefaultSession {
- user: {
- id: string;
- // ...other properties
- // role: UserRole;
- } & DefaultSession["user"];
- }
-
- // interface User {
- // // ...other properties
- // // role: UserRole;
- // }
-}
+import { DrizzleAdapter } from "@auth/drizzle-adapter";
+import NextAuth, { DefaultSession } from "next-auth";
+import { Adapter } from "next-auth/adapters";
+import Google from "next-auth/providers/google";
+import { db } from "./db";
+import { createTable } from "./db/schema";
-/**
- * Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
- *
- * @see https://next-auth.js.org/configuration/options
- */
-export const authOptions: NextAuthOptions = {
+export const {
+ handlers: { GET, POST },
+ auth,
+} = NextAuth({
+ secret: env.NEXTAUTH_SECRET,
callbacks: {
- session: ({ session, token }) => ({
+ session: ({session, token}) => ({
...session,
user: {
...session.user,
- id: token.id,
+ id: token.id as string,
token
},
})
},
adapter: DrizzleAdapter(db, createTable) as Adapter,
providers: [
- GoogleProvider({
+ Google({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
+ authorization: {
+ params: {
+ prompt: "consent",
+ response_type: "code",
+ },
+ },
}),
- /**
- * ...add more providers here.
- *
- * Most other providers require a bit more work than the Discord provider. For example, the
- * GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
- * model. Refer to the NextAuth.js docs for the provider you want to use. Example:
- *
- * @see https://next-auth.js.org/providers/github
- */
],
-};
-
-/**
- * Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
- *
- * @see https://next-auth.js.org/configuration/nextjs
- */
-export const getServerAuthSession = () => getServerSession(authOptions);
+});
diff --git a/apps/web/src/server/db/index.ts b/apps/web/src/server/db/index.ts
index 5c2246d5..bdfa2968 100644
--- a/apps/web/src/server/db/index.ts
+++ b/apps/web/src/server/db/index.ts
@@ -1,12 +1,8 @@
-import Database from "better-sqlite3";
-import { drizzle } from "drizzle-orm/better-sqlite3";
+import { drizzle } from 'drizzle-orm/d1';
-import { env } from "@/env.js";
import * as schema from "./schema";
export const db = drizzle(
- new Database(env.DATABASE_URL, {
- fileMustExist: false,
- }),
+ process.env!.D1Database! as unknown as D1Database,
{ schema }
);