From e575b981e3e0a986ed146bcf791fe990d85c9e72 Mon Sep 17 00:00:00 2001 From: noahgerard Date: Tue, 3 Sep 2024 18:02:07 -0400 Subject: [PATCH] refactor: Remove unused imports and dependencies in auth.ts, githubauth.ts, and googleauth.ts --- src/server/lib/auth.ts | 2 -- src/server/lib/githubauth.ts | 29 +---------------------------- src/server/lib/googleauth.ts | 26 -------------------------- 3 files changed, 1 insertion(+), 56 deletions(-) diff --git a/src/server/lib/auth.ts b/src/server/lib/auth.ts index 0aac7e3..d9ab9d1 100644 --- a/src/server/lib/auth.ts +++ b/src/server/lib/auth.ts @@ -2,8 +2,6 @@ username/password. please check https://lucia-auth.com/ for more information. */ -"use server"; - import { PrismaAdapter } from "@lucia-auth/adapter-prisma"; import { verify } from "@node-rs/argon2"; import { hash } from "@node-rs/argon2"; diff --git a/src/server/lib/githubauth.ts b/src/server/lib/githubauth.ts index 2cb7ba1..8dddf0b 100644 --- a/src/server/lib/githubauth.ts +++ b/src/server/lib/githubauth.ts @@ -3,11 +3,7 @@ we use lucia and arctic for third-parth authentication. check https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps and https://arctic.js.org/providers/github for more information. */ -import { PrismaAdapter } from "@lucia-auth/adapter-prisma"; import { GitHub } from "arctic"; -import { Lucia } from "lucia"; -import { db } from "~/server/db"; -import type { DatabaseUserAttributes } from "./auth"; if (!process.env.GITHUB_CLIENT_ID) { throw new Error("GITHUB_CLIENT_ID is not defined"); @@ -21,31 +17,8 @@ if (!process.env.GITHUB_CALLBACK_URL) { throw new Error("GITHUB_CALLBACK_URL is not defined"); } -const adapter = new PrismaAdapter(db.session, db.user); export const github = new GitHub( process.env.GITHUB_CLIENT_ID, process.env.GITHUB_CLIENT_SECRET, { redirectURI: process.env.GITHUB_CALLBACK_URL }, -); - -export const lucia = new Lucia(adapter, { - sessionCookie: { - expires: false, - attributes: { - secure: process.env.NODE_ENV === "production", - }, - }, - getUserAttributes: (attributes: DatabaseUserAttributes) => { - return { - githubId: attributes.github_id, - username: attributes.username, - }; - }, -}); - -declare module "lucia" { - interface Register { - Lucia: typeof lucia; - DatabaseUserAttributes: DatabaseUserAttributes; - } -} +); \ No newline at end of file diff --git a/src/server/lib/googleauth.ts b/src/server/lib/googleauth.ts index 41ea77e..9a1224e 100644 --- a/src/server/lib/googleauth.ts +++ b/src/server/lib/googleauth.ts @@ -5,11 +5,7 @@ check https://developers.google.com/identity/protocols/oauth2 and https://arctic.js.org/providers/google for more information. */ -import { PrismaAdapter } from "@lucia-auth/adapter-prisma"; import { Google } from "arctic"; -import { Lucia } from "lucia"; -import { db } from "../db"; -import type { DatabaseUserAttributes } from "./auth"; if (!process.env.GOOGLE_CLIENT_ID) { throw new Error("Missing GOOGLE_CLIENT_ID"); @@ -21,34 +17,12 @@ if (!process.env.GOOGLE_CALLBACK_URL) { throw new Error("Missing GOOGLE_CALLBACK_URL"); } -const adapter = new PrismaAdapter(db.session, db.user); export const google = new Google( process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET, process.env.GOOGLE_CALLBACK_URL, ); -export const lucia = new Lucia(adapter, { - sessionCookie: { - expires: false, - attributes: { - secure: process.env.NODE_ENV === "production", - }, - }, - getUserAttributes: (attributes: DatabaseUserAttributes) => { - return { - email: attributes.email, - }; - }, -}); - -declare module "lucia" { - interface Register { - Lucia: typeof lucia; - DatabaseUserAttributes: DatabaseUserAttributes; - } -} - export const randInt = (max: number) => { return Math.floor(Math.random() * max); };