-
Notifications
You must be signed in to change notification settings - Fork 0
Charef/taa 252 update the theauthapi code samples js #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
533f707
3a76975
21f7bfa
9731188
6839223
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ async function createApiKeySample() { | |
| featureFlagOne: true, | ||
| featureFlagTwo: false, | ||
| }, | ||
| expiry: new Date("2023-09-01 00:00:00"), // optional expiry date | ||
| expiry: "2023-09-01 00:00:00", // optional expiry date | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one works, but I'm curios on why you're favoring expiry as string instead of a date object 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The date object was causing an error when posting to the server. I removed it for speed! |
||
| rateLimitConfigs: { | ||
| rateLimit: 60, | ||
| rateLimitTtl: 60, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,36 +2,34 @@ require("dotenv").config(); | |
| const TheAuthAPI = require("theauthapi").default; | ||
|
|
||
| const apiUrl = process.env.production | ||
| ? "https://api.theauthapi.com" | ||
| : process.env.TESTING_URL; | ||
| ? "https://api.theauthapi.com" | ||
| : process.env.TESTING_URL; | ||
| const theAuthAPI = new TheAuthAPI(process.env.ACCESS_TOKEN, { host: apiUrl }); | ||
|
|
||
|
|
||
| async function fetchKeysSample() { | ||
| // fetch all api keys | ||
| const apiKeys = await theAuthAPI.apiKeys.getKeys(); | ||
| console.log('all keys', apiKeys); | ||
| console.log("all keys", apiKeys); | ||
|
|
||
| // fetch keys with a specific name | ||
| // fetch keys with a specific name (1st one from the list returned previously) | ||
| const nameFilteredKeys = await theAuthAPI.apiKeys.getKeys({ | ||
| name: "new api key" | ||
| name: apiKeys.length === 0 ? "YOUR_NAME_FILTER" : apiKeys[0].name, | ||
| }); | ||
| console.log('Keys filtered using name', nameFilteredKeys); | ||
| console.log("Keys filtered using name", nameFilteredKeys); | ||
|
|
||
| // fetch keys where customUserId is null | ||
| const customUserIdFilteredKey = await theAuthAPI.apiKeys.getKeys({ | ||
| customUserId: null, | ||
| }) | ||
| console.log('Keys filtered using customUserId', customUserIdFilteredKey); | ||
| customUserId: "null", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think leaving this as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The server borked with the |
||
| }); | ||
| console.log("Keys filtered using customUserId", customUserIdFilteredKey); | ||
|
|
||
| // fetch inactive (revoked) keys | ||
| const inactiveKeys = await theAuthAPI.apiKeys.getKeys({ | ||
| isActive: false, | ||
| }) | ||
| console.log('Inactive (revoked) keys', inactiveKeys); | ||
| }); | ||
| console.log("Inactive (revoked) keys", inactiveKeys); | ||
| } | ||
|
|
||
| (async () => { | ||
| await fetchKeysSample(); | ||
| })(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works fine,
expiryis expected to be aDateobject, we want the users to use the library just like any other JS code, passingexpiryas a date feels more natural in a JS environmentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment before. Can you test using the JS Date object?