- Updated the ProtectedRoute component to improve access control logic, including a timeout mechanism for handling authentication checks. - Refactored the checkAccess function to streamline user access verification based on roles and authentication status. - Added comments for clarity on the authentication flow and the use of the convexClient plugin in the auth.ts file. - Improved the overall structure and readability of the code in auth.ts and ProtectedRoute.svelte.
19 lines
847 B
TypeScript
19 lines
847 B
TypeScript
/**
|
|
* 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";
|
|
|
|
// O baseURL deve apontar para o frontend (SvelteKit), não para o Convex diretamente
|
|
// O Better Auth usa as rotas HTTP do Convex que são acessadas via proxy do SvelteKit
|
|
// ou diretamente se configurado. Com o plugin convexClient, o token é gerenciado automaticamente.
|
|
export const authClient = createAuthClient({
|
|
// baseURL padrão é window.location.origin, que é o correto para SvelteKit
|
|
// O Better Auth será acessado via rotas HTTP do Convex registradas em http.ts
|
|
plugins: [convexClient()],
|
|
});
|