add config for if github auth is enabled. room for more...

This commit is contained in:
Thomas Ruoff
2026-03-03 22:21:34 +01:00
parent 899bc86967
commit e3d67fbe8a
3 changed files with 10 additions and 3 deletions

View File

@@ -42,7 +42,6 @@ Auth is handled by `better-auth` via `lib/auth.ts` (server) and `lib/auth-client
- `ADMIN_EMAIL` — Only email allowed to log in - `ADMIN_EMAIL` — Only email allowed to log in
- `BETTER_AUTH_SECRET` — Auth secret key - `BETTER_AUTH_SECRET` — Auth secret key
- `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` — GitHub OAuth app (optional) - `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET` — GitHub OAuth app (optional)
- `NEXT_PUBLIC_GITHUB_ENABLED` — Set to enable GitHub OAuth login on the client
- `SMTP_USER` / `SMTP_PASS` / `FROM_EMAIL` — Email via wirtanen.uberspace.de:465 - `SMTP_USER` / `SMTP_PASS` / `FROM_EMAIL` — Email via wirtanen.uberspace.de:465
- `GOOGLE_CALENDAR_ID` — Calendar to sync bookings into - `GOOGLE_CALENDAR_ID` — Calendar to sync bookings into
- `GOOGLE_SERVICE_ACCOUNT_KEY_JSON` — Service account credentials (JSON string) - `GOOGLE_SERVICE_ACCOUNT_KEY_JSON` — Service account credentials (JSON string)

7
helpers/config.ts Normal file
View File

@@ -0,0 +1,7 @@
const { GITHUB_CLIENT_SECRET, GITHUB_CLIENT_ID } = process.env;
export function getConfig() {
return {
githubAuthEnabled: Boolean(GITHUB_CLIENT_SECRET?.length && GITHUB_CLIENT_ID?.length),
};
}

View File

@@ -4,6 +4,7 @@ import { mongodbAdapter } from "better-auth/adapters/mongodb"
import { MongoClient, ServerApiVersion } from "mongodb" import { MongoClient, ServerApiVersion } from "mongodb"
import { MONGO_URI } from "../db" import { MONGO_URI } from "../db"
import nodemailer from "nodemailer" import nodemailer from "nodemailer"
import { getConfig } from "../helpers/config"
async function sendEmail({ to, subject, url }: { to: string; subject: string; url: string }) { async function sendEmail({ to, subject, url }: { to: string; subject: string; url: string }) {
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
@@ -28,7 +29,7 @@ const ADMIN_EMAIL = process.env.ADMIN_EMAIL
const GITHUB_USERS_GRANTED = ['111471'] const GITHUB_USERS_GRANTED = ['111471']
const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID; const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID;
const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET; const GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET;
const GITHUB_ENABLED = Boolean(GITHUB_CLIENT_SECRET?.length && GITHUB_CLIENT_ID?.length); const { githubAuthEnabled } = getConfig();
const client = new MongoClient(MONGO_URI, { const client = new MongoClient(MONGO_URI, {
serverApi: { serverApi: {
@@ -47,7 +48,7 @@ export const auth = betterAuth({
}, },
}), }),
], ],
...(GITHUB_ENABLED ? { ...(githubAuthEnabled ? {
socialProviders: { socialProviders: {
github: { github: {
provider: 'github', provider: 'github',