WIP: A simple cli for daily tangled use cases and AI integration. This is for my personal use right now, but happy if others get mileage from it! :)
1import type { TangledApiClient } from '../lib/api-client.js';
2
3/**
4 * Validate that the client is authenticated and has an active session
5 * @throws Error if not authenticated or no session found
6 * @returns The current session with did and handle
7 */
8export async function requireAuth(client: TangledApiClient): Promise<{
9 did: string;
10 handle: string;
11}> {
12 if (!(await client.isAuthenticated())) {
13 throw new Error('Must be authenticated. Run "tangled auth login" first.');
14 }
15
16 const session = client.getSession();
17 if (!session) {
18 throw new Error('No active session found');
19 }
20
21 return session;
22}