Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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}`)
})
over 4 years ago · Santiago Trujillo Report

0

Auth.currentSession() will return a CognitoUserSession containing accessToken, idToken, and refreshToken.

The CognitoUserSession is actually the following: CognitoUserSession {idToken: CognitoIdToken, refreshToken: CognitoRefreshToken, accessToken: CognitoAccessToken, clockDrift: 0}

Accessing pairs within that object can be achieved through straightforward dot notation at this point.


Example: Retrieve the accessToken and log to console

Auth.currentSession().then(data => console.log(data.accessToken));

The result will be a CognitoAccessToken in the form CognitoAccessToken { jwtToken: '', payload: ''}

If you just want the jwtToken within the CognitoAccessToken, it's just dot notation all the way down (with log to console example):

Auth.currentSession().then(data => console.log(data.accessToken.jwtToken));

Note: This method also refreshes the current session if needed (reference).

over 4 years ago · Santiago Trujillo Report

0

I believe you can do

Auth.currentCredentials(credentials => {
  const tokens = Auth.essentialCredentials(credentials);
})

where essentialCredentials will return all of the tokens

Hope this helps.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!