M-Gabrielly fb578b2a7a feat(api): add server-side /api/create-user route (user creation not functional yet)
- What was done:
  - Added a server-side Next.js route at `src/app/api/create-user/route.ts` that validates the requester token, checks roles, generates a temporary password and forwards the creation to the Supabase Edge Function using the service role key.
  - Client wired to call the route via `lib/config.ts` (`FUNCTIONS_ENDPOINTS.CREATE_USER` -> `/api/create-user`) and the `criarUsuario()` wrapper in `lib/api.ts`.
- Status / missing work:
  - Important: user creation is NOT working yet (requests to `/api/create-user` return 404 in dev).
  - Next steps: restart dev server, ensure `SUPABASE_SERVICE_ROLE_KEY` is set in the environment, check server logs and run a test POST with a valid admin JWT.
2025-10-14 17:02:26 -03:00

34 lines
1.1 KiB
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`,
// Use internal Next.js server route which performs privileged operations
// with the service role key. Client should call this route instead of
// calling the Supabase Edge Function directly.
CREATE_USER: `/api/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}`;
}