Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

654 B
Raw Blame
import { httpClient, HttpMethod } from '@activepieces/pieces-common';

export function normalizeHost(host: string): string {
  return host.replace(/\/+$/, '');
}

export async function pocketbaseAuthenticate(host: string, email: string, password: string): Promise<string> {
  const response = await httpClient.sendRequest({
    method: HttpMethod.POST,
    url: `${host}/api/collections/_superusers/auth-with-password`,
    body: {
      identity: email,
      password: password,
    },
  });

  const token = response.body?.token;
  if (!token) {
    throw new Error('Authentication failed: no token returned from PocketBase.');
  }

  return token;
}