How to use the megalodon.refreshToken function in megalodon

To help you get started, we’ve selected a few megalodon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h3poteto / whalebird-desktop / src / main / account.ts View on Github external
let json = {}
    try {
      const res = await client.get('/accounts/verify_credentials')
      json = {
        username: res.data.username,
        accountId: res.data.id,
        avatar: res.data.avatar
      }
    } catch (err) {
      log.error(err)
      log.info('Get new access token using refresh token...')
      // If failed to fetch account, get new access token usign refresh token.
      if (!account.refreshToken) {
        throw new RefreshTokenDoesNotExist()
      }
      const token = await Mastodon.refreshToken(account.clientId, account.clientSecret, account.refreshToken, account.baseURL, proxy)
      client = new Mastodon(token.access_token, account.baseURL + '/api/v1', 'Whalebird', proxy)
      const res = await client.get('/accounts/verify_credentials')
      json = {
        username: res.data.username,
        accountId: res.data.id,
        avatar: res.data.avatar,
        accessToken: token.accessToken,
        refreshToken: token.refreshToken
      }
    }
    return this.updateAccount(account._id!, json)
  }

megalodon

Fediverse API client for node.js and browser

MIT
Latest version published 1 month ago

Package Health Score

69 / 100
Full package analysis