Skip to content

Commit

Permalink
added expiration date functionality (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
shariqanwar20 committed Aug 29, 2021
1 parent 65d0d69 commit 6667a31
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/lib/configStore.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
const Configstore = require("configstore");
const fs = require("fs");
import axios from "axios";
const dotenv = require("dotenv").configure({});
require("dotenv").config()

export const isSessionTokenActive = async (): Promise<boolean> => {
const config = new Configstore("panacloud");

export const isSessionTokenActive = async (): Promise<boolean> => {
const config = new Configstore("panacloud");
try {
if (fs.existsSync(config.path)) {
/* config file exists, confirm with API that is this token valid */
console.log(config.path);

const { API_ENDPOINT } = process.env;
// console.log(API_ENDPOINT);

const tokenFile = JSON.parse(fs.readFileSync(config.path));
console.log(tokenFile);

const { data } = await axios.post(
process.env.APIENDPOINT!,
API_ENDPOINT!,
{
query: `
query EntityProfile {
getEntityProfile(input: {requestedEntityType: USER, requesterEntityId: "${tokenFile.entityId}", requesterEntityType: USER, requestedEntityId: "${tokenFile.entityId}"}) {
getEntityProfile(input: {requestedEntityType: USER, requesterEntityId: "${tokenFile.user.id}", requesterEntityType: USER, requestedEntityId: "${tokenFile.user.id}"}) {
id
... on userFullProfileInfo {
id
Expand All @@ -32,17 +35,22 @@ export const isSessionTokenActive = async (): Promise<boolean> => {
},
{
headers: {
Authorization: `Bearer ${tokenFile.sessionToken}`,
Authorization: `Bearer ${tokenFile.auth.token}`,
},
}
);
console.log(data);
// console.log(data);

if (data.data.getEntityProfile.publicAddress) return true;
else return false;
}
else {
if (
(data.data.getEntityProfile.id === tokenFile.user.id) &&
(Date.now() < tokenFile.auth.expiry_date * 1000)
) {
return true;
} else {
return false;
}
} else {
return false;
}
} catch (error) {
return false;
Expand Down

0 comments on commit 6667a31

Please sign in to comment.