Skip to content

Commit

Permalink
Switch userinfo endpoint (#807)
Browse files Browse the repository at this point in the history
* 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
Regalijan and Neztore authored Aug 1, 2024
1 parent 700e0db commit 9c93841
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ noblox.onBlurbChange = require('./users/onBlurbChange.js')
noblox.clearSession = require('./util/clearSession.js')
noblox.generalRequest = require('./util/generalRequest.js')
noblox.getAction = require('./util/getAction.js')
noblox.getAuthenticatedUser = require('./util/getAuthenticatedUser.js')
noblox.getCurrentUser = require('./util/getCurrentUser.js')
noblox.getGeneralToken = require('./util/getGeneralToken.js')
noblox.getHash = require('./util/getHash.js')
Expand Down
41 changes: 41 additions & 0 deletions lib/util/getAuthenticatedUser.js
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
}
6 changes: 6 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,12 @@ declare module "noblox.js" {
IsPremium: boolean
}

interface AuthenticatedUserData {
id: number;
name: string;
displayName: string;
}

interface UserLoginApiData {
userId: number;
}
Expand Down
9 changes: 9 additions & 0 deletions typings/jsDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,15 @@ type LoggedInUserData = {
IsPremium: boolean
}

/**
* @typedef
*/
type AuthenticatedUserData = {
id: number;
name: string;
displayName: string;
}

/**
* @typedef
*/
Expand Down

0 comments on commit 9c93841

Please sign in to comment.