Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

365
Visualizações
Unhandled Runtime Error SyntaxError: Unexpected end of JSON input from SignIn or SignOut next-auth

I have next an Unhandled Runtime Error SyntaxError: Unexpected end of JSON input when I use SignIn or SignOut with auth credentials.

The error is something weird because show the pop up next error, but register the token and session

Error

This is my authorization code with credentials:

CredentialsProvider({
      id: 'credentials',
      name: 'Credenciales',

      async authorize(credentials, req) {
        if (!(credentials.email.length > 0) || !(credentials.password.length > 0)) {
          throw new Error('Email or password was not provided');
        }
        const formData = new FormData();
        formData.append('username', credentials.email);
        formData.append('password', credentials.password);
        formData.append('client_id', credentials.rif);
        
        const url = `${process.env.BACK_ENDPOINT}/login/`
        
        const response = await fetch(url,{
          method: 'POST',
          body: formData
        });
        if (response.status === 401) {
          return {
            'details': 'error',
            'message': 'The username or password is not valid'
          }
        }
      
        if (response.status === 500) {
          throw new Error('Have been an error');
        }
        const data = await response.json();
        if (response.status > 400 && response.status < 500) {
          console.error(data)
          if (data.detail) {
            throw data.message;
          }
          throw data;
        }
        if(data.details === 'success'){
          return data
        }
        return null
      }
    }),

This is my signIn Callback:

signIn: async({ user, account, profile, email, credentials }) => {  
      // console.log('signIn', {user, account, profile, email, credentials})
      if (account.type === 'credentials'){
        if(user.details === 'success') return true
        if(user.details === 'error') return false
      }
},

And this is my onsubmit handle in frontend:

      const objectValues= {
        email: values.email,
        password: values.password,
        rif: values.rif,
        callbackUrl: '/',
      }
      signIn('credentials', objectValues)
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I find the 'error': in callbacks from [...nextauth].js I had the redirect calback without anything there, it always executes with no return:

Callbacks:{
    jwt: ({token, user, account, isNewUser}) =>{
        some code...
    },

    redirect: async ({url, baseUrl}) => { 
        // NOTHING OF CODE
    },

    session: ({session, token}) => {
        some code...
    },

    signIn: async({ user, account, profile, email, credentials }) => {
        some code...
    }  
}

Next time I'm going to give more details about my code and the problem, sorry. Thanks @Bravo for your time.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda