feat: edge ready

This commit is contained in:
Henry
2024-01-03 12:31:52 +00:00
parent 20ef0f5ca2
commit 0ba6528c12
8 changed files with 4002 additions and 43 deletions

View File

@@ -26,7 +26,7 @@
"drizzle-orm": "^0.28.5", "drizzle-orm": "^0.28.5",
"formik": "^2.4.5", "formik": "^2.4.5",
"next": "^13.5.4", "next": "^13.5.4",
"next-auth": "^4.24.4", "next-auth": "0.0.0-manual.cfb42ae7",
"react": "18.2.0", "react": "18.2.0",
"react-beautiful-dnd": "^13.1.1", "react-beautiful-dnd": "^13.1.1",
"react-contenteditable": "^3.3.7", "react-contenteditable": "^3.3.7",

3976
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
import Image from "next/image"; import Image from "next/image";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { getServerAuthSession } from "~/server/auth"; import { auth } from "~/server/auth";
import boardsIcon from "~/app/assets/boards.json"; import boardsIcon from "~/app/assets/boards.json";
@@ -12,7 +12,7 @@ const navigation = [
]; ];
export default async function Layout(props: { children: React.ReactNode }) { export default async function Layout(props: { children: React.ReactNode }) {
const session = await getServerAuthSession(); const session = await auth();
if (!session?.user) redirect("api/auth/signin"); if (!session?.user) redirect("api/auth/signin");

View File

@@ -1,11 +1,5 @@
import NextAuth from "next-auth"; export { GET, POST } from "~/server/auth";
import { authOptions } from "~/server/auth"; export const runtime = "edge";
export const preferredRegion = 'lhr1';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment export const dynamic = 'force-dynamic'
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
// export const runtime = "edge";
// export const preferredRegion = 'lhr1';
// export const dynamic = 'force-dynamic'

View File

@@ -23,6 +23,6 @@ const handler = (req: NextRequest) =>
export { handler as GET, handler as POST }; export { handler as GET, handler as POST };
// export const runtime = "edge"; export const runtime = "edge";
// export const preferredRegion = 'lhr1'; export const preferredRegion = 'lhr1';
// export const dynamic = 'force-dynamic' export const dynamic = 'force-dynamic'

View File

@@ -2,17 +2,17 @@ import { Login } from "~/app/_components/auth";
export default function LoginPage() { export default function LoginPage() {
return ( return (
<main className="bg-dark-50 flex h-screen flex-col items-center justify-center"> <main className="flex h-screen flex-col items-center justify-center bg-dark-50">
<h1 className="text-dark-1000 mb-6 text-lg font-normal tracking-tight"> <h1 className="mb-6 text-lg font-normal tracking-tight text-dark-1000">
貫 kan 貫 kan
</h1> </h1>
<p className="text-dark-1000 mb-10 text-3xl">Get started</p> <p className="mb-10 text-3xl text-dark-1000">Get started</p>
<div className="bg-dark-400 border-dark-600 w-full rounded-md border px-10 py-10 sm:max-w-md"> <div className="w-full rounded-md border border-dark-600 bg-dark-300 px-10 py-10 sm:max-w-md">
<div className=" sm:mx-auto sm:w-full sm:max-w-sm"> <div className=" sm:mx-auto sm:w-full sm:max-w-sm">
<Login /> <Login />
</div> </div>
</div> </div>
<p className="text-dark-1000 mt-10 text-center text-sm"> <p className="mt-10 text-center text-sm text-dark-1000">
{"Already have an account?"} {"Already have an account?"}
</p> </p>
</main> </main>

View File

@@ -12,7 +12,7 @@ import { type NextRequest } from "next/server";
import superjson from "superjson"; import superjson from "superjson";
import { ZodError } from "zod"; import { ZodError } from "zod";
import { getServerAuthSession } from "~/server/auth"; import { auth } from "~/server/auth";
import { db } from "~/server/db"; import { db } from "~/server/db";
/** /**
@@ -38,7 +38,7 @@ interface CreateContextOptions {
* @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts * @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts
*/ */
export const createInnerTRPCContext = async (opts: CreateContextOptions) => { export const createInnerTRPCContext = async (opts: CreateContextOptions) => {
const session = await getServerAuthSession(); const session = await auth();
return { return {
session, session,

View File

@@ -1,9 +1,5 @@
import { DrizzleAdapter } from "@auth/drizzle-adapter"; import { DrizzleAdapter } from "@auth/drizzle-adapter";
import { import NextAuth, { type DefaultSession } from "next-auth";
getServerSession,
type DefaultSession,
type NextAuthOptions,
} from "next-auth";
import { db } from "~/server/db"; import { db } from "~/server/db";
import { mySqlTable } from "~/server/db/schema"; import { mySqlTable } from "~/server/db/schema";
@@ -29,18 +25,18 @@ declare module "next-auth" {
// } // }
} }
/** export const {
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc. handlers: { GET, POST },
* auth,
* @see https://next-auth.js.org/configuration/options } = NextAuth({
*/
export const authOptions: NextAuthOptions = {
callbacks: { callbacks: {
session: ({ session, user }) => ({ session: ({ session, user }) => ({
...session, ...session,
user: { user: {
...session.user,
id: user.id, id: user.id,
name: session.user.name,
email: session.user.email,
image: session.user.image,
}, },
}), }),
}, },
@@ -82,11 +78,4 @@ export const authOptions: NextAuthOptions = {
}, },
} }
], ],
}; });
/**
* 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);