- Adds Next.js route src/app/api/create-user/route.ts for secure creation (JWT validation, password generation). - Adds client fallback in lib/api.ts: signup via /auth/v1/signup then call create-user Edge Function. - Wires CredentialsDialog into registration forms and maps RLS errors to a user-friendly message. - Removes banner from pp/paciente/page.tsx. NOTE: Not fully resolved — requires SUPABASE_SERVICE_ROLE_KEY on server and/or RLS policy changes; server route needs Next.js restart.
31 lines
962 B
TypeScript
31 lines
962 B
TypeScript
import { ENV_CONFIG } from './env-config';
|
|
|
|
export const API_CONFIG = {
|
|
BASE_URL: ENV_CONFIG.SUPABASE_URL + "/rest/v1",
|
|
TIMEOUT: 30000,
|
|
VERSION: "v1",
|
|
} as const;
|
|
|
|
export const AUTH_ENDPOINTS = {
|
|
LOGIN: `${ENV_CONFIG.SUPABASE_URL}/auth/v1/token`,
|
|
LOGOUT: `${ENV_CONFIG.SUPABASE_URL}/auth/v1/logout`,
|
|
USER: `${ENV_CONFIG.SUPABASE_URL}/auth/v1/user`,
|
|
} as const;
|
|
|
|
export const FUNCTIONS_ENDPOINTS = {
|
|
USER_INFO: `${ENV_CONFIG.SUPABASE_URL}/functions/v1/user-info`,
|
|
CREATE_USER: `${ENV_CONFIG.SUPABASE_URL}/functions/v1/create-user`,
|
|
} as const;
|
|
|
|
export const API_KEY = ENV_CONFIG.SUPABASE_ANON_KEY;
|
|
|
|
export const DEFAULT_HEADERS = {
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
} as const;
|
|
|
|
export function buildApiUrl(endpoint: string): string {
|
|
const baseUrl = API_CONFIG.BASE_URL.replace(/\/$/, '');
|
|
const cleanEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
return `${baseUrl}${cleanEndpoint}`;
|
|
} |