import type { tipoResposta } from "p-respostas" import { urlAutenticacao } from "./_urlAutenticacao" type tipoPostValidarTokem = { token: string } import node_fetch from "cross-fetch" import type { z } from "zod" import type { zAmbiente } from "../ts/ambiente" /** faz a validação do token */ export const validarToken = async ({ ambiente, post, }: { ambiente: z.infer post: tipoPostValidarTokem }): Promise<"valido" | "erro"> => { const url = `${urlAutenticacao(ambiente)}/api/validar_token` try { const resposta = await node_fetch(url, { method: "POST", body: JSON.stringify(post), headers: { "Content-Type": "application/json" }, }) .then((r) => r.json()) .then((r) => r as tipoResposta) .then((resposta) => resposta.eCerto ? ("valido" as const) : ("erro" as const), ) .catch(() => "erro" as const) return resposta } catch (_e) { return "erro" } }