Skip to content

Commit 3049783

Browse files
Merge pull request #102 from ConsenSys/user_info
Add method to get user info
2 parents fd47a8d + 790a684 commit 3049783

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,31 @@ class Client {
250250
}
251251
}
252252

253+
/**
254+
* Retrieves info about the current logged-in user
255+
*
256+
* @returns Object containing user info
257+
**/
258+
async getUserInfo () {
259+
await this.login()
260+
261+
const url = libUtil.joinUrl(this.apiUrl.href, `${defaultApiVersion}/users`)
262+
let userInfo
263+
try {
264+
userInfo = await simpleRequester.do({ url, accessToken: this.accessToken, json: true })
265+
} catch (e) {
266+
if (e.status !== 401) {
267+
throw e
268+
}
269+
const tokens = await refresh.do(this.accessToken, this.refreshToken, this.apiUrl)
270+
this.accessToken = tokens.access
271+
this.refreshToken = tokens.refresh
272+
273+
userInfo = await simpleRequester.do({ url, accessToken: this.accessToken, json: true })
274+
}
275+
return userInfo
276+
}
277+
253278
async getStatus (uuid, inputApiUrl = defaultApiUrl) {
254279
const url = libUtil.joinUrl(this.apiUrl.href, `${defaultApiVersion}/analyses/${uuid}`)
255280
return this.getStatusOrIssues(uuid, url, inputApiUrl)

0 commit comments

Comments
 (0)