add consultaUsuariosexterno

This commit is contained in:
Luiz H. R. Silva 2024-06-05 19:40:12 -03:00
parent 07a656a2b4
commit 9491278d6c
62 changed files with 489 additions and 200 deletions

View file

@ -0,0 +1,32 @@
import type { tipoResposta } from "p-respostas"
import { urlAutenticacao } from "./_urlAutenticacao"
type tipoPostValidarTokem = { token: string }
/** faz a validação do token */
export const validarToken = async ({
ambiente,
post,
buscar,
}: {
ambiente: "desenvolvimento" | "producao"
post: tipoPostValidarTokem
/** função que conecta com a API */
buscar: (
url: string,
post: tipoPostValidarTokem,
) => Promise<tipoResposta<any>>
}): Promise<"valido" | "erro"> => {
const url = `${urlAutenticacao(ambiente)}/api/validar_token`
try {
const resposta = await buscar(url, post)
.then((resposta) =>
resposta.eCerto ? ("valido" as const) : ("erro" as const),
)
.catch(() => "erro" as const)
return resposta
} catch (e) {
return "erro"
}
}