melhorias em validar token

This commit is contained in:
Luiz Silva 2025-11-18 15:10:17 -03:00
parent e0a492f7d2
commit 947ffdc815
6 changed files with 13 additions and 16 deletions

View file

@ -31,6 +31,7 @@ __export(validarToken_exports, {
validarToken: () => validarToken
});
module.exports = __toCommonJS(validarToken_exports);
var import_p_respostas = require("p-respostas");
var import_cross_fetch = __toESM(require("cross-fetch"));
var import_site_autenticacao = require("../utilitarios/site_autenticacao");
const validarToken = async ({
@ -43,12 +44,10 @@ const validarToken = async ({
method: "POST",
body: JSON.stringify(post),
headers: { "Content-Type": "application/json" }
}).then((r) => r.json()).then((r) => r).then(
(resposta2) => resposta2.eCerto ? "valido" : "erro"
).catch(() => "erro");
}).then((r) => r.json()).then((r) => r).catch((err) => import_p_respostas.respostaComuns.erro(`Erro: ${err.message}`));
return resposta;
} catch (_e) {
return "erro";
} catch (err) {
return import_p_respostas.respostaComuns.erro(`Erro: ${err.message}`);
}
};
// Annotate the CommonJS export names for ESM import in node:

View file

@ -39,7 +39,7 @@ declare const pAutenticacao: {
post: {
token: string;
};
}) => Promise<"valido" | "erro">;
}) => Promise<p_respostas.tipoResposta<string>>;
codigoContaSite: ({ base_url_autenticacao, post, }: {
base_url_autenticacao: string;
post: {

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "p-autenticacao-drive",
"version": "1.45.0",
"version": "1.46.0",
"description": "",
"main": "./src/index.ts",
"exports": {

Binary file not shown.

View file

@ -1,4 +1,4 @@
import type { tipoResposta } from "p-respostas"
import { respostaComuns, type tipoResposta } from "p-respostas"
type tipoPostValidarTokem = { token: string }
@ -12,7 +12,7 @@ export const validarToken = async ({
}: {
base_url_autenticacao: string
post: tipoPostValidarTokem
}): Promise<"valido" | "erro"> => {
}): Promise<tipoResposta<string>> => {
const url = `${site_autenticacao(base_url_autenticacao)}/api/validar_token`
try {
@ -23,13 +23,11 @@ export const validarToken = async ({
})
.then((r) => r.json())
.then((r) => r as tipoResposta<any>)
.then((resposta) =>
resposta.eCerto ? ("valido" as const) : ("erro" as const),
)
.catch(() => "erro" as const)
.catch((err) => respostaComuns.erro(`Erro: ${(err as Error).message}`))
return resposta
} catch (_e) {
return "erro"
} catch (err) {
return respostaComuns.erro(`Erro: ${(err as Error).message}`)
}
}