Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda