Skip to content

Commit

Permalink
refactor: Remove unused imports and dependencies in auth.ts, githubau…
Browse files Browse the repository at this point in the history
…th.ts, and googleauth.ts
  • Loading branch information
noahgerard committed Sep 3, 2024
1 parent 7b0d4d9 commit e575b98
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 56 deletions.
2 changes: 0 additions & 2 deletions src/server/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
29 changes: 1 addition & 28 deletions src/server/lib/githubauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
}
);
26 changes: 0 additions & 26 deletions src/server/lib/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
};

0 comments on commit e575b98

Please sign in to comment.