mirror of
https://github.com/rybbit-io/rybbit.git
synced 2025-05-10 20:05:38 +02:00
add new user (#18)
This commit is contained in:
parent
8ada9b8c16
commit
61d64c1293
17 changed files with 586 additions and 42 deletions
|
@ -1,5 +1,5 @@
|
|||
import { betterAuth } from "better-auth";
|
||||
import { username } from "better-auth/plugins";
|
||||
import { username, admin } from "better-auth/plugins";
|
||||
import dotenv from "dotenv";
|
||||
import pg from "pg";
|
||||
|
||||
|
@ -7,7 +7,31 @@ dotenv.config();
|
|||
|
||||
type AuthType = ReturnType<typeof betterAuth> | null;
|
||||
|
||||
export let auth: AuthType | null = null;
|
||||
export let auth: AuthType | null = 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,
|
||||
},
|
||||
deleteUser: {
|
||||
enabled: true,
|
||||
},
|
||||
plugins: [username(), admin()],
|
||||
trustedOrigins: [],
|
||||
advanced: {
|
||||
useSecureCookies: process.env.NODE_ENV === "production", // don't mark Secure in dev
|
||||
defaultCookieAttributes: {
|
||||
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
|
||||
path: "/",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const initAuth = (allowList: string[]) => {
|
||||
auth = betterAuth({
|
||||
|
@ -25,7 +49,7 @@ export const initAuth = (allowList: string[]) => {
|
|||
deleteUser: {
|
||||
enabled: true,
|
||||
},
|
||||
plugins: [username()],
|
||||
plugins: [username(), admin()],
|
||||
trustedOrigins: allowList,
|
||||
advanced: {
|
||||
useSecureCookies: process.env.NODE_ENV === "production", // don't mark Secure in dev
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue