mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
add config for if github auth is enabled. room for more...
This commit is contained in:
@@ -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
|
||||
- `BETTER_AUTH_SECRET` — Auth secret key
|
||||
- `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
|
||||
- `GOOGLE_CALENDAR_ID` — Calendar to sync bookings into
|
||||
- `GOOGLE_SERVICE_ACCOUNT_KEY_JSON` — Service account credentials (JSON string)
|
||||
|
||||
7
helpers/config.ts
Normal file
7
helpers/config.ts
Normal 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),
|
||||
};
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { mongodbAdapter } from "better-auth/adapters/mongodb"
|
||||
import { MongoClient, ServerApiVersion } from "mongodb"
|
||||
import { MONGO_URI } from "../db"
|
||||
import nodemailer from "nodemailer"
|
||||
import { getConfig } from "../helpers/config"
|
||||
|
||||
async function sendEmail({ to, subject, url }: { to: string; subject: string; url: string }) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
@@ -28,7 +29,7 @@ const ADMIN_EMAIL = process.env.ADMIN_EMAIL
|
||||
const GITHUB_USERS_GRANTED = ['111471']
|
||||
const GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID;
|
||||
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, {
|
||||
serverApi: {
|
||||
@@ -47,7 +48,7 @@ export const auth = betterAuth({
|
||||
},
|
||||
}),
|
||||
],
|
||||
...(GITHUB_ENABLED ? {
|
||||
...(githubAuthEnabled ? {
|
||||
socialProviders: {
|
||||
github: {
|
||||
provider: 'github',
|
||||
|
||||
Reference in New Issue
Block a user