This commit is contained in:
Luiz H. R. Silva 2024-06-04 11:11:32 -03:00
parent d1afd7376f
commit af92778e98
6 changed files with 35 additions and 23 deletions

View file

@ -1,23 +1,28 @@
import type { tipoResposta } from "~comuns"
type tipoPostValidarTokem = { token: string }
/** retorna uma url e os parametros que devem ser enviádos */
const urlValidarToken = async ({
const urlAutenticacao = (ambiente: "desenvolvimento" | "producao") =>
`${
ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030"
}/autenticacao`
/** faz a validação do token */
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 = `${
ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030"
}/autenticacao/api/validar_token`
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/validar_token`
try {
const resposta = await buscar(url, post)
@ -31,5 +36,6 @@ const urlValidarToken = async ({
return "erro"
}
}
/** todas as rotas de comunicação com autenticador partem dessa variável */
export const pAutenticacao = { urlValidarToken }
export const pAutenticacao = { validarToken, urlAutenticacao }