Skip to content

Commit

Permalink
fix: send sessionToken with apiRequest for correct rate-limiting
Browse files Browse the repository at this point in the history
* added endpoint to track and implenented in start function

* add event names enum

* handle cases when start function is called without serverurl

* send sessionToken in request when making api calls.

* use Moralis object to get applicationId
and user data

Co-authored-by: Erno <[email protected]>
  • Loading branch information
sogunshola and ErnoW authored Mar 15, 2022
1 parent 9e21fa3 commit bef928b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/genSolanaAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ static async fetchFromServer(name, options) {
try {
const http = axios.create({ baseURL: this.serverUrl });
const user = this.Moralis.User.current();
if(user) {
options._SessionToken = user.attributes.sessionToken;
options._ApplicationId = this.Moralis.applicationId;
}
const response = await http.post(\`/functions/sol-\${name}\`, options, {
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
Expand Down
5 changes: 5 additions & 0 deletions scripts/genWeb3API.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ static async fetchFromServer(name, options) {
try {
const http = axios.create({ baseURL: this.serverUrl });
if (!options.chain) options.chain = 'eth';
const user = this.Moralis.User.current();
if(user) {
options._SessionToken = user.attributes.sessionToken;
options._ApplicationId = this.Moralis.applicationId;
}
const response = await http.post(\`/functions/\${name}\`, options, {
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
Expand Down
5 changes: 5 additions & 0 deletions src/MoralisSolanaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ static async fetchFromServer(name, options) {

try {
const http = axios.create({ baseURL: this.serverUrl });
const user = this.Moralis.User.current();
if(user) {
options._SessionToken = user.attributes.sessionToken;
options._ApplicationId = this.Moralis.applicationId;
}

const response = await http.post(`/functions/sol-${name}`, options, {
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
Expand Down
5 changes: 5 additions & 0 deletions src/MoralisWeb3Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ static async fetchFromServer(name, options) {
try {
const http = axios.create({ baseURL: this.serverUrl });
if (!options.chain) options.chain = 'eth';
const user = this.Moralis.User.current();
if(user) {
options._SessionToken = user.attributes.sessionToken;
options._ApplicationId = this.Moralis.applicationId;
}

const response = await http.post(`/functions/${name}`, options, {
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
Expand Down

0 comments on commit bef928b

Please sign in to comment.