Merge pull request #1106 from OpenSignLabs/validation

fix: api token not visible
This commit is contained in:
prafull-opensignlabs
2024-08-27 13:26:09 +05:30
committed by GitHub
2 changed files with 24 additions and 8 deletions
+12 -6
View File
@@ -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
@@ -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 });