feat: integrate Better Auth and enhance authentication flow

- Added Better Auth integration to the web application, allowing for dual login support with both custom and Better Auth systems.
- Updated authentication client configuration to dynamically set the base URL based on the environment.
- Enhanced chat components to utilize user authentication status, improving user experience and security.
- Refactored various components to support Better Auth, including error handling and user identity management.
- Improved notification handling and user feedback mechanisms during authentication processes.
This commit is contained in:
2025-11-06 09:35:36 -03:00
parent 33f305220b
commit 06f03b53e5
28 changed files with 4109 additions and 436 deletions

View File

@@ -1,7 +1,21 @@
import { createAuthClient } from "better-auth/client";
/**
* Cliente Better Auth para frontend SvelteKit
*
* Configurado para trabalhar com Convex via plugin convexClient.
* Este cliente será usado para autenticação quando Better Auth estiver ativo.
*/
import { createAuthClient } from "better-auth/svelte";
import { convexClient } from "@convex-dev/better-auth/client/plugins";
export const authClient = createAuthClient({
baseURL: "http://localhost:5173",
plugins: [convexClient()],
// Base URL da API Better Auth (mesma do app)
baseURL: typeof window !== "undefined"
? window.location.origin // Usar origem atual em produção
: "http://localhost:5173", // Fallback para desenvolvimento
plugins: [
// Plugin Convex integra Better Auth com Convex backend
convexClient({
convexUrl: import.meta.env.PUBLIC_CONVEX_URL || "",
}),
],
});