From 7b7b10c9a5b4f0d5eca097c73345e22e4a897b7a Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Tue, 27 Aug 2024 13:22:48 +0530 Subject: [PATCH] fix: api token visible --- apps/OpenSign/src/pages/GenerateToken.js | 18 ++++++++++++------ .../cloud/parsefunction/getapitoken.js | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/OpenSign/src/pages/GenerateToken.js b/apps/OpenSign/src/pages/GenerateToken.js index 0cbcfa198..52fcd2413 100644 --- a/apps/OpenSign/src/pages/GenerateToken.js +++ b/apps/OpenSign/src/pages/GenerateToken.js @@ -14,8 +14,8 @@ import Parse from "parse"; function GenerateToken() { const { t } = useTranslation(); - const [parseBaseUrl] = useState(localStorage.getItem("baseUrl")); - const [parseAppId] = useState(localStorage.getItem("parseAppId")); + const parseBaseUrl = localStorage.getItem("baseUrl"); + const parseAppId = localStorage.getItem("parseAppId"); const [apiToken, SetApiToken] = useState(""); const [isLoader, setIsLoader] = useState(true); const [isModal, setIsModal] = useState({ @@ -49,11 +49,17 @@ function GenerateToken() { const subscribe = await checkIsSubscribed(); setIsSubscribe(subscribe); } - const res = await Parse.Cloud.run("getapitoken"); + const url = parseBaseUrl + "functions/getapitoken"; + const headers = { + "Content-Type": "application/json", + "X-Parse-Application-Id": parseAppId, + sessiontoken: localStorage.getItem("accesstoken") + }; + const res = await axios.post(url, {}, { headers: headers }); if (res) { const allowedapis = await Parse.Cloud.run("allowedapis"); setAmount((obj) => ({ ...obj, totalapis: allowedapis })); - SetApiToken(res?.result); + SetApiToken(res?.data?.result?.result); } setIsLoader(false); } catch (err) { @@ -122,7 +128,7 @@ function GenerateToken() { const price = quantity > 0 ? (Math.round(quantity * amount.priceperapi * 100) / 100).toFixed(2) - : 500 * amount.priceperapi; + : (Math.round(500 * amount.priceperapi * 100) / 100).toFixed(2); setAmount((prev) => ({ ...prev, quantity: quantity, price: price })); }; const handleAddOnApiSubmit = async (e) => { @@ -138,7 +144,7 @@ function GenerateToken() { if (_resAddon.status === "success") { setAmount((obj) => ({ ...obj, - quantity: 1, + quantity: 500, priceperapi: 0.15, price: (75.0).toFixed(2), totalapis: _resAddon.addon diff --git a/apps/OpenSignServer/cloud/parsefunction/getapitoken.js b/apps/OpenSignServer/cloud/parsefunction/getapitoken.js index b76217f85..0f051e011 100644 --- a/apps/OpenSignServer/cloud/parsefunction/getapitoken.js +++ b/apps/OpenSignServer/cloud/parsefunction/getapitoken.js @@ -1,7 +1,17 @@ +import axios from 'axios'; +import { cloudServerUrl } from '../../Utils.js'; + export default async function getapitoken(request) { try { - if (request?.user) { - const userId = request?.user?.id; + const serverUrl = cloudServerUrl; //process.env.SERVER_URL; + const userRes = await axios.get(serverUrl + '/users/me', { + headers: { + 'X-Parse-Application-Id': process.env.APP_ID, + 'X-Parse-Session-Token': request.headers['sessiontoken'], + }, + }); + const userId = userRes.data && userRes.data.objectId; + if (userId) { const tokenQuery = new Parse.Query('appToken'); tokenQuery.equalTo('userId', { __type: 'Pointer', className: '_User', objectId: userId }); const res = await tokenQuery.first({ useMasterKey: true });