Skip to content
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

fix: Fix TokenResponse Type #105

Closed
wants to merge 1 commit into from

Conversation

ncronquist
Copy link

  • The TokenResponse type was unioning to different types and so only
    the shared keys, oauth_callback_confirmed, were actually available as
    keys on that type
  • This change switches TokenResponse back to an interface and uses
    optional properties for keys that may not be present

Notes

  • This fix resolved a typing error for me where the following wouldn't work:
// Property 'oauth_token' does not exist on type 'TokenResponse'.ts(2339)
const { oauth_token } = await client.getRequestToken("http://localhost:4000/auth/callback/twitter")
  • That said, I'm new to typescript so I apologize if there is a more standard way to handle this

- The TokenResponse type was unioning to different types and so only
  the shared keys, oauth_callback_confirmed, were actually available as
  keys on that type
- This change switches TokenResponse back to an interface and uses
  optional properties for keys that may not be present
@ciffelia
Copy link
Collaborator

Try this:

const oauthResult = await client.getRequestToken(callbackUrl)

if (oauthResult.oauth_callback_confirmed === 'true') {
  // in this scope you can access oauth_token and oauth_token_secret
  console.log(oauthResult.oauth_token)
} else {
  // in this scope oauth_token and oauth_token_secret are not available
  throw new Error('oauth_callback_confirmed is not "true".')
}

@ciffelia ciffelia closed this Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants