This commit is contained in:
Luiz H. R. Silva 2024-06-04 10:44:32 -03:00
parent 43616225e7
commit 7e7fbb6809
17 changed files with 159 additions and 18 deletions

49
src/autenticacao.ts Normal file
View file

@ -0,0 +1,49 @@
type tipoPostValidarTokem = { token: string }
/** retorna uma url e os parametros que devem ser enviádos */
const urlValidarToken = async ({
ambiente,
post,
buscar,
}: {
ambiente: "desenvolvimento" | "producao"
post: tipoPostValidarTokem
buscar: (
url: string,
post: tipoPostValidarTokem,
) => Promise<
| {
cod: 200
valor: any
eCerto: true
eErro: false
mensagem: undefined
}
| {
cod: 400
valor: any
eCerto: false
eErro: true
mensagem: string
}
>
}): Promise<"valido" | "erro"> => {
const url = `${
ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030"
}/autenticacao/api/validar_token`
try {
const resposta = await buscar(url, post)
.then((resposta) =>
resposta.eCerto ? ("valido" as const) : ("erro" as const),
)
.catch((e) => "erro" as const)
return resposta
} catch (e) {
return "erro"
}
}
/** todas as rotas de comunicação com autenticador partem dessa variável */
export const pAutenticacao = { urlValidarToken }