mirror of
https://github.com/rybbit-io/rybbit.git
synced 2025-05-10 20:05:38 +02:00
load trustedOrigins from db
This commit is contained in:
parent
08435e4c3c
commit
e1f299fc8a
4 changed files with 47 additions and 33 deletions
|
@ -2,26 +2,35 @@ import { betterAuth } from "better-auth";
|
|||
import pg from "pg";
|
||||
import { username } from "better-auth/plugins";
|
||||
import dotenv from "dotenv";
|
||||
import { sql } from "../db/postgres/postgres.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export const auth = betterAuth({
|
||||
basePath: "/auth",
|
||||
database: new pg.Pool({
|
||||
host: process.env.POSTGRES_HOST || "postgres",
|
||||
port: parseInt(process.env.POSTGRES_PORT || "5432", 10),
|
||||
database: process.env.POSTGRES_DB,
|
||||
user: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
}),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
plugins: [username()],
|
||||
trustedOrigins: [
|
||||
"http://localhost:3002",
|
||||
"http://localhost:3001",
|
||||
"https://tracking.tomato.gg",
|
||||
"https://tomato.gg",
|
||||
],
|
||||
});
|
||||
type AuthType = ReturnType<typeof betterAuth> | null;
|
||||
|
||||
export let auth: AuthType | null = null;
|
||||
|
||||
export const initAuth = async () => {
|
||||
const domains = await sql`SELECT domain FROM sites`;
|
||||
console.info(domains);
|
||||
auth = betterAuth({
|
||||
basePath: "/auth",
|
||||
database: new pg.Pool({
|
||||
host: process.env.POSTGRES_HOST || "postgres",
|
||||
port: parseInt(process.env.POSTGRES_PORT || "5432", 10),
|
||||
database: process.env.POSTGRES_DB,
|
||||
user: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
}),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
plugins: [username()],
|
||||
trustedOrigins: [
|
||||
"http://localhost:3002",
|
||||
"http://localhost:3001",
|
||||
"https://tracking.tomato.gg",
|
||||
...domains.map(({ domain }) => `https://${domain}`),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue