forked from yellicode/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the validation functionality so now the existing sessiontoken i…
…s used if it is valid (#50)
- Loading branch information
1 parent
2248f7f
commit e62c6e1
Showing
4 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
const Configstore = require("configstore") | ||
const fs = require("fs") | ||
const Configstore = require("configstore"); | ||
const fs = require("fs"); | ||
import axios from "axios"; | ||
|
||
export const isSessionTokenActive = (sessionToken: string) => { | ||
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 tokenFile = JSON.parse(fs.readFileSync(config.path)) | ||
console.log(tokenFile.sessionToken); | ||
return true; | ||
/* config file exists, confirm with API that is this token valid */ | ||
console.log(config.path); | ||
|
||
const tokenFile = JSON.parse(fs.readFileSync(config.path)); | ||
|
||
const { data } = await axios.post( | ||
"https://kvnqyzqjgjf2bkgdubxgsz7dle.appsync-api.us-east-1.amazonaws.com/graphql", | ||
{ | ||
query: ` | ||
query EntityProfile { | ||
getEntityProfile(input: {requestedEntityType: USER, requesterEntityId: "${tokenFile.entityId}", requesterEntityType: USER, requestedEntityId: "${tokenFile.entityId}"}) { | ||
id | ||
... on userFullProfileInfo { | ||
id | ||
publicAddress | ||
firstName | ||
lastName | ||
} | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${tokenFile.sessionToken}`, | ||
}, | ||
} | ||
); | ||
console.log(data); | ||
|
||
if (data.data.getEntityProfile.publicAddress) return true; | ||
else return false; | ||
} | ||
else { | ||
return false; | ||
} | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters