diff options
Diffstat (limited to 'apps/web/src/server')
| -rw-r--r-- | apps/web/src/server/auth.ts | 79 | ||||
| -rw-r--r-- | apps/web/src/server/db/index.ts | 8 |
2 files changed, 23 insertions, 64 deletions
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 } ); |