mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-06-10 07:16:01 +00:00
feat(auth): permite bloquear novos cadastros
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { passkey } from "@better-auth/passkey";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { APIError, betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import type { GoogleProfile } from "better-auth/social-providers";
|
||||
import { isSignupDisabled } from "@/shared/lib/auth/signup";
|
||||
import { seedDefaultCategoriesForUser } from "@/shared/lib/categories/defaults";
|
||||
import { db, schema } from "@/shared/lib/db";
|
||||
import { ensureDefaultPayerForUser } from "@/shared/lib/payers/defaults";
|
||||
@@ -122,6 +123,13 @@ export const auth = betterAuth({
|
||||
databaseHooks: {
|
||||
user: {
|
||||
create: {
|
||||
before: async () => {
|
||||
if (!isSignupDisabled()) return;
|
||||
|
||||
throw new APIError("FORBIDDEN", {
|
||||
message: "Novos cadastros estão desativados.",
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Após criar novo usuário, inicializa:
|
||||
* 1. Categorias padrão (Receitas/Despesas)
|
||||
|
||||
4
src/shared/lib/auth/signup.ts
Normal file
4
src/shared/lib/auth/signup.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export function isSignupDisabled(): boolean {
|
||||
const value = process.env.DISABLE_SIGNUP?.trim().toLowerCase();
|
||||
return value === "true";
|
||||
}
|
||||
Reference in New Issue
Block a user