mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-28 10:49:41 +02:00
fix: validation of generate token
This commit is contained in:
@@ -1,29 +1,24 @@
|
||||
import axios from 'axios';
|
||||
import { cloudServerUrl } from '../../Utils.js';
|
||||
export default async function getapitoken(request) {
|
||||
const serverUrl = cloudServerUrl; //process.env.SERVER_URL;
|
||||
try {
|
||||
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) {
|
||||
if (request?.user) {
|
||||
const userId = request?.user?.id;
|
||||
const tokenQuery = new Parse.Query('appToken');
|
||||
tokenQuery.equalTo('userId', { __type: 'Pointer', className: '_User', objectId: userId });
|
||||
const res = await tokenQuery.first({ useMasterKey: true });
|
||||
if (res) {
|
||||
return { status: 'success', result: res.get('token') };
|
||||
} else {
|
||||
return { error: 'api token found.' };
|
||||
}
|
||||
} else {
|
||||
return { error: 'Invalid session token.' };
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Err in getapitoken', err);
|
||||
if (err.code == 209) {
|
||||
return { error: 'Invalid session token' };
|
||||
return { error: 'Invalid session token.' };
|
||||
} else {
|
||||
return { error: "You don't have access!" };
|
||||
return { error: "You don't have access." };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user