actions.ts32 lines · main
1'use server';
2
3import { redirect } from 'next/navigation';
4
5import { apiFetch } from '../../../lib/api';
6
7interface CliTokenResp {
8 token: string;
9}
10
11export async function allow(
12 { redirectUrl, state }: { redirectUrl: string; state: string },
13): Promise<void> {
14 const res = await apiFetch('/v1/auth/cli-token', { method: 'POST' });
15 if (!res.ok) {
16 throw new Error(`mint failed: ${res.status}`);
17 }
18 const body = (await res.json()) as CliTokenResp;
19 const u = new URL(redirectUrl);
20 u.searchParams.set('token', body.token);
21 u.searchParams.set('state', state);
22 redirect(u.toString());
23}
24
25export async function deny(
26 { redirectUrl, state }: { redirectUrl: string; state: string },
27): Promise<void> {
28 const u = new URL(redirectUrl);
29 u.searchParams.set('denied', '1');
30 u.searchParams.set('state', state);
31 redirect(u.toString());
32}