aws-amplify Authentication...how to access tokens on successful Auth.signIn?

spencewine picture spencewine · Feb 14, 2018 · Viewed 12.6k times · Source

I'm trying to figure out how to access the accessToken, refreshToken, and idToken that I receive back from aws-amplify using the Auth library.

example in docs: https://aws.github.io/aws-amplify/media/authentication_guide.html

example of my usage:

const user = await Auth.signIn(email, password);

user has a bunch of properties that are inaccessible including everything I need. In the docs, it's unclear how to get to these properties because the examples all log the result. Any ideas?

Answer

Omar picture Omar · May 19, 2019
Auth.currentSession().then(res=>{
  let accessToken = res.getAccessToken()
  let jwt = accessToken.getJwtToken()
  //You can print them to see the full objects
  console.log(`myAccessToken: ${JSON.stringify(accessToken)}`)
  console.log(`myJwt: ${jwt}`)
})