Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔒 Local Auth Improvements #449

Merged
merged 4 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 85 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@trpc/next": "^10.21.1",
"@trpc/react-query": "^10.21.1",
"@trpc/server": "^10.9.0",
"@types/lodash": "^4.14.194",
"@uiball/loaders": "^1.2.6",
"@upstash/ratelimit": "^0.4.2",
"@vercel/analytics": "^1.0.0",
Expand All @@ -36,14 +37,16 @@
"cheerio": "^1.0.0-rc.12",
"chromadb": "^1.4.1",
"clsx": "^1.2.1",
"cookies-next": "^2.1.1",
"framer-motion": "^10.11.2",
"html-to-image": "^1.11.11",
"i18next": "^22.4.15",
"langchain": "^0.0.63",
"lodash": "^4.17.21",
"micro": "^10.0.1",
"micro-cors": "^0.1.1",
"next": "13.1.6",
"next-auth": "^4.19.0",
"next-auth": "4.19.0",
"next-i18next": "^13.2.2",
"nextjs-google-analytics": "^2.3.3",
"react": "18.2.0",
Expand Down
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ else
printf $ENV > .env
./prisma/useSqlite.sh
npm install
prisma db push
npm run dev
fi
4 changes: 1 addition & 3 deletions src/components/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ const Drawer = ({
session={session}
/>
))}
{env.NEXT_PUBLIC_FF_AUTH_ENABLED && (
<AuthItem session={session} signIn={signIn} signOut={signOut} />
)}
<AuthItem session={session} signIn={signIn} signOut={signOut} />
<DrawerItem
icon={<FaQuestionCircle />}
text={`${t("HELP_BUTTON", { ns: "drawer" })}`}
Expand Down
22 changes: 6 additions & 16 deletions src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ const requiredForProduction = () =>
process.env.NODE_ENV === "production"
? z.string().min(1).trim()
: z.string().min(1).trim().optional();

const requiredAuthEnabledForProduction = () => {
return process.env.NODE_ENV === "production" &&
process.env.NEXT_PUBLIC_FF_AUTH_ENABLED === "true"
? z.string().min(1).trim()
: z.string().min(1).trim().optional();
};

function stringToBoolean() {
return z.preprocess((str) => str === "true", z.boolean());
}
Expand All @@ -38,12 +30,12 @@ export const serverSchema = z.object({
),
OPENAI_API_KEY: z.string(),

GOOGLE_CLIENT_ID: requiredAuthEnabledForProduction(),
GOOGLE_CLIENT_SECRET: requiredAuthEnabledForProduction(),
GITHUB_CLIENT_ID: requiredAuthEnabledForProduction(),
GITHUB_CLIENT_SECRET: requiredAuthEnabledForProduction(),
DISCORD_CLIENT_ID: requiredAuthEnabledForProduction(),
DISCORD_CLIENT_SECRET: requiredAuthEnabledForProduction(),
GOOGLE_CLIENT_ID: z.string().min(1).trim().optional(),
GOOGLE_CLIENT_SECRET: z.string().min(1).trim().optional(),
GITHUB_CLIENT_ID: z.string().min(1).trim().optional(),
GITHUB_CLIENT_SECRET: z.string().min(1).trim().optional(),
DISCORD_CLIENT_ID: z.string().min(1).trim().optional(),
DISCORD_CLIENT_SECRET: z.string().min(1).trim().optional(),

STRIPE_SECRET_KEY: z.string().optional(),
STRIPE_WEBHOOK_SECRET: z.string().optional(),
Expand Down Expand Up @@ -93,7 +85,6 @@ export const clientSchema = z.object({
.string()
.transform((str) => str === "true")
.optional(),
NEXT_PUBLIC_FF_AUTH_ENABLED: stringToBoolean(),
NEXT_PUBLIC_WEB_SEARCH_ENABLED: stringToBoolean(),
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: z.string().optional(),
NEXT_PUBLIC_FF_SUB_ENABLED: stringToBoolean(),
Expand All @@ -111,7 +102,6 @@ export const clientEnv = {
NEXT_PUBLIC_VERCEL_ENV: process.env.NEXT_PUBLIC_VERCEL_ENV ?? "development",
NEXT_PUBLIC_STRIPE_DONATION_ENABLED:
process.env.NEXT_PUBLIC_STRIPE_DONATION_ENABLED,
NEXT_PUBLIC_FF_AUTH_ENABLED: process.env.NEXT_PUBLIC_FF_AUTH_ENABLED,
NEXT_PUBLIC_WEB_SEARCH_ENABLED: process.env.NEXT_PUBLIC_WEB_SEARCH_ENABLED,
NEXT_PUBLIC_VERCEL_URL:
process.env.NEXT_PUBLIC_VERCEL_URL ?? "http://localhost:3000",
Expand Down
8 changes: 7 additions & 1 deletion src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import NextAuth from "next-auth";
import { authOptions } from "../../../server/auth";
import type { NextApiRequest, NextApiResponse } from "next";

export default NextAuth(authOptions);
const auth = (req: NextApiRequest, res: NextApiResponse) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return NextAuth(req, res, authOptions(req, res));
};

export default auth;
69 changes: 0 additions & 69 deletions src/server/auth.ts

This file was deleted.

Loading