Skip to content

Commit

Permalink
fix: api token visible
Browse files Browse the repository at this point in the history
  • Loading branch information
prafull-opensignlabs committed Aug 27, 2024
1 parent bd4d333 commit 7b7b10c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 12 additions & 6 deletions apps/OpenSign/src/pages/GenerateToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions apps/OpenSignServer/cloud/parsefunction/getapitoken.js
Original file line number Diff line number Diff line change
@@ -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 });
Expand Down

0 comments on commit 7b7b10c

Please sign in to comment.