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

340
Visualizações
Sending a MSAL token to backend using Axios

I am trying to send user id which is being previously decoded from JWT token (together with data inputted by user). Unfortunately, at the moment when I try to send it, I am getting an exception in the backend saying that data in the request array is null:

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'Approver1lvl', table 'Requests'; column does not allow nulls. INSERT fails.

Judging by the console log info I see in the browser, the token is decoded correctly. So, that makes me think that there is a mistake in the customInstance.post part.

Here is my code:

export default function NewRequest() {
  const [userData, setUserData] = useState({
    firstName: "",
    surname: "",
    co: "",
    homeAddress: "",
    postCode: "",
    city: "",
    country: "",
    phonePrefix: "",
    phoneNumber: "",
    email: "",
    approver1lvl: "",
    employeeId: "",
    userId: ""
  });

 const handleSubmit = () => {
    var token = localStorage.getItem("msal.idtoken");
    var jwt = jwt_decode(token);
    const {
      firstName,
      surname,
      co,
      homeAddress,
      postCode,
      city,
      country,
      phonePrefix,
      phoneNumber,
      email,
      approver1lvl,
      employeeId,
      date,
    } = userData;

    const user = {
      firstName,
      surname,
      co,
      homeAddress,
      postCode,
      city,
      country,
      phonePrefix,
      phoneNumber,
      email,
      approver1lvl,
      employeeId,
      birth,
    };

   
    customInstance.post("Request",  {user, userId: jwt.oid}).then((response) => {});
  };

Does anyone knows how to fix that?

EDIT: Screenshot of an error in the browser: enter image description here

EDIT2: I have successfully send a POST using swagger, which looked like this: enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I see in the Swagger that userId is in the same level as email, phone ..., I think it should work like this:

export default function NewRequest() {
  const [userData, setUserData] = useState({
    firstName: "",
    surname: "",
    co: "",
    homeAddress: "",
    postCode: "",
    city: "",
    country: "",
    phonePrefix: "",
    phoneNumber: "",
    email: "",
    approver1lvl: "",
    employeeId: "",
    userId: ""
  });

 const handleSubmit = () => {
    var token = localStorage.getItem("msal.idtoken");
    var jwt = jwt_decode(token);
    const {
      firstName,
      surname,
      co,
      homeAddress,
      postCode,
      city,
      country,
      phonePrefix,
      phoneNumber,
      email,
      approver1lvl,
      employeeId,
      date,
    } = userData;

    const user = {
      firstName,
      surname,
      co,
      homeAddress,
      postCode,
      city,
      country,
      phonePrefix,
      phoneNumber,
      email,
      approver1lvl,
      employeeId,
      birth,
    };

   
    customInstance.post("Request",  {...user, userId: jwt.oid}).then((response) => {});
  };
about 4 years ago · Juan Pablo Isaza 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