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

151
Views
cognitoUser.refreshSession keeps refreshing user login

Im trying to refresh the jwt token with cognitoUser.refreshSession, everytime I log in it simply refreshes the login page and asks me to sign in again

I have written up some code from various examples I have found but still struggle to get it going. If anyone has any suggestions I would welcome them:

Code as follows:

import axios from 'axios';
import { Auth } from 'aws-amplify';

const httpClient = axios.create(
  { baseURL: process.env.VUE_APP_API_BASE_URL }
);

const refreshToken = async function() {
    try {
        const cognitoUser = await Auth.currentAuthenticatedUser();
        const currentSession = await Auth.currentSession();
        cognitoUser.refreshSession(currentSession.refreshToken, (err, session) => {
            console.log('session', err, session);
            return Auth.user.signInUserSession.idToken.jwtToken
        });
    } catch (e) {
        console.log('Unable to refresh Token', e);
    }
}

httpClient.interceptors.request.use(
  config => {
    const idToken = refreshToken()
    config.headers.Authorization = idToken;
    return config
  }, error => Promise.reject(error))


export default httpClient;
about 4 years ago · Juan Pablo Isaza
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!