-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update current user endpoint * Update typings for LoggedInUserData * Revert "Update typings for LoggedInUserData" This reverts commit 2e000b2. * Revert "Update current user endpoint" This reverts commit 00ae4b9. * Create getAuthenticatedUser function * Add AuthenticatedUserData type * Add file extension to getAuthenticatedUser require * Fix linting --------- Co-authored-by: Josh Muir <[email protected]>
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Includes | ||
const http = require('./http.js').func | ||
|
||
// Args | ||
exports.optional = ['jar'] | ||
|
||
// Docs | ||
/** | ||
* 🔐 Get the current authenticated user. | ||
* @category Utility | ||
* @alias getAuthenticatedUser | ||
* @returns {AuthenticatedUserData} | ||
* @example const noblox = require("noblox.js") | ||
* // Login using your cookie. | ||
* const user = await noblox.getAuthenticatedUser() | ||
**/ | ||
|
||
// Define | ||
exports.func = async function (args) { | ||
const jar = args.jar | ||
const httpOpt = { | ||
url: '//users.roblox.com/v1/users/authenticated', | ||
options: { | ||
method: 'GET', | ||
followRedirect: false, | ||
jar, | ||
json: true, | ||
resolveWithFullResponse: true | ||
} | ||
} | ||
|
||
const res = await http(httpOpt) | ||
|
||
if (res.statusCode === 401) { | ||
throw new Error('You are not logged in.') | ||
} else if (res.statusCode !== 200) { | ||
throw new Error(JSON.stringify(res.body)) | ||
} | ||
|
||
return res.body | ||
} |
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