title: Session expires when redirect to a page
body: <p>In my application, once a user logs in, taken to the home page where he can view his details. There is a button "Edit Profile" where the user will be taken to a page where he can edit the data. Once the editing  successes, he is redirected back to the home page. But here, it is redirected to the login page. I think the session is expired unexpectedly. How to overcome this issue?</p>
  
  <p>// This is my update info controller</p>
  
  <pre><code>/**
   * @Route("/update/{id}", name="update")
   * @param $id
   * @param Request $request
   * @param UserPasswordEncoderInterface $passwordEncoder
   * @param UserInterface $loggedUser
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
   */
  
  public function updateUser($id,Request $request, UserPasswordEncoderInterface $passwordEncoder, UrlGeneratorInterface $urlGenerator){
  
      $loggedUser = $this-&gt;get('security.token_storage')-&gt;getToken()-&gt;getUser()-&gt;getId();
  
      if ($id == $loggedUser){
          $em = $this-&gt;getDoctrine()-&gt;getManager();
          $conn =$em-&gt;getConnection();
          $user = $em-&gt;find(User::class,$id);
  
          $form = $this-&gt;createForm(RegisterType::class,$user, [
              'validation_groups' =&gt; ['update'],
          ]);
  
  
          $form-&gt;handleRequest($request);
  
          if($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
              $file = $request-&gt;files-&gt;get('register')['image'];
              if($file){
                  $fileName = md5(uniqid()).'.'.$file-&gt;guessExtension();
                  $file-&gt;move(
                      $this-&gt;getParameter('uploads_dir'), $fileName
                  );
                  $user-&gt;setImage($fileName);
              }
  
              if($user-&gt;getPassword() !="") {
                  $user-&gt;setPassword($passwordEncoder-&gt;encodePassword($user,$user-&gt;getPassword()));
  
                  $sql = '
                      UPDATE user
                      SET first_name = :firstName, last_name = :lastName, id_number = :idNumber, phone_number = :phoneNumber, address = :address, password = :password
                      WHERE id= :id
      ';
                  $stmt = $conn-&gt;prepare($sql);
                  $stmt-&gt;execute(['firstName' =&gt; $user-&gt;getFirstName(),
                      'lastName' =&gt; $user-&gt;getLastName(),
                      'idNumber' =&gt; $user-&gt;getIdNumber(),
                      'phoneNumber' =&gt; $user-&gt;getPhoneNumber(),
                      'address' =&gt; $user-&gt;getAddress(),
                      'password' =&gt; $user-&gt;getPassword(),
                      'id' =&gt; $id]);
              } else {
                  $sql = '
                      UPDATE user
                      SET first_name = :firstName, last_name = :lastName, id_number = :idNumber, phone_number = :phoneNumber, address = :address
                      WHERE id= :id
      ';
                  $stmt = $conn-&gt;prepare($sql);
                  $stmt-&gt;execute(['firstName' =&gt; $user-&gt;getFirstName(),
                      'lastName' =&gt; $user-&gt;getLastName(),
                      'idNumber' =&gt; $user-&gt;getIdNumber(),
                      'phoneNumber' =&gt; $user-&gt;getPhoneNumber(),
                      'address' =&gt; $user-&gt;getAddress(),
                      'id' =&gt; $id]);
              }
  
  
  
              return new RedirectResponse($urlGenerator-&gt;generate('home'));
          }
      } else {
          return new RedirectResponse($urlGenerator-&gt;generate('home'));
      }
  
      return $this-&gt;render('register/update.html.twig', [
          'form'=&gt;$form-&gt;createView(),
      ]);
  }
  </code></pre>
  
  <p>// This is RegisterType form</p>
  
  <pre><code>class RegisterType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('email',EmailType::class,[
                  'label'=&gt;'Email',
                  'required' =&gt; false,
                  'attr'=&gt;['placeholder'=&gt;"Email"]
              ])
              -&gt;add('password',RepeatedType::class,[
                  'type' =&gt; PasswordType::class,
                  'invalid_message' =&gt; 'The password fields must match.',
                  'required' =&gt; false,
                  'options' =&gt; ['attr' =&gt; ['class' =&gt; 'password-field']],
                  'first_options'  =&gt; ['label' =&gt; 'Password','attr'=&gt;['placeholder'=&gt;"Password"]],
                  'second_options' =&gt; ['label' =&gt; 'Confirm Password','attr'=&gt;['placeholder'=&gt;"Confirm Password"]],
              ])
              -&gt;add('firstName',TextType::class,['label'=&gt;'First Name',  'attr'=&gt;['placeholder'=&gt;"First Name"]])
              -&gt;add('lastName',TextType::class,['label'=&gt;'Last Name','attr'=&gt;['placeholder'=&gt;"Last Name"]])
              -&gt;add('address',TextareaType::class,['required' =&gt; false,'label'=&gt;'Address','attr'=&gt;['placeholder'=&gt;"Address"]])
              -&gt;add('idNumber',TextType::class,['label'=&gt;'NIC Number','attr'=&gt;['placeholder'=&gt;"NIC Number"]])
              -&gt;add('phoneNumber',TelType::class,['label'=&gt;'Phone Number','attr'=&gt;['placeholder'=&gt;"Phone Number"]])
              -&gt;add('image',FileType::class,['label'=&gt;'Photo','required'=&gt;false,'attr'=&gt;['hidden'=&gt;"hidden", 'accept'=&gt;"image/jpeg, image/png"]])
              -&gt;add('save',SubmitType::class,[
                  'label'=&gt;'Register',
                  'attr' =&gt; [
                      'class'=&gt;"btn btn-outline-success float-right"
                  ]
              ])
  
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; User::class,
          ]);
      }
  }
  </code></pre>
  
  <p>// This is my User Class</p>
  
  <pre><code>class User implements UserInterface{
  
  /**
   * @ORM\Id()
   * @ORM\GeneratedValue()
   * @ORM\Column(type="integer")
   */
  private $id;
  
  /**
       * @ORM\Column(type="string", length=180, unique=true)
   * @Assert\Email()
   * @Assert\NotBlank()
   */
  private $email;
  
  /**
   * @ORM\Column(type="json")
   */
  private $roles = [];
  
  /**
   * @var string The hashed password
   * @ORM\Column(type="string")
   * @Assert\NotBlank()
   */
  private $password;
  
  /**
   * @ORM\Column(type="string",length=255)
   * @Assert\NotBlank(groups={"update"})
   *
   */
  private $firstName;
  
  /**
   * @ORM\Column(type="string",length=255)
   * @Assert\NotBlank(groups={"update"})
   */
  private $lastName;
  
  /**
   * @ORM\Column(type="string",length=255,nullable=true)
   *
   */
  private $image;
  
  /**
   * @ORM\Column(type="string", nullable=true)
   */
  private $address;
  
  /**
   * @ORM\Column(type="string",length=10)
   * @Assert\Length("10",groups={"update"})
   */
  private $phoneNumber;
  
  /**
   * @ORM\Column(type="string",length=10)
   * @Assert\NotBlank(groups={"update"})
   * @Assert\Length("10",groups={"update"})
   */
  private $idNumber;
  
  /**
   * @ORM\OneToMany(targetEntity="App\Entity\Vehicle", mappedBy="user")
   */
  private $vehicle;
  
  /**
   * @ORM\OneToOne(targetEntity="App\Entity\Account", inversedBy="user")
   */
  private $account;
  
  
  public function __construct()
  {
      $this-&gt;vehicle = new ArrayCollection();
  }
  
  public function getId(): ?int
  {
      return $this-&gt;id;
  }
  
  public function getEmail()
  {
      return $this-&gt;email;
  }
  
  public function setEmail( $email): self
  {
      $this-&gt;email = $email;
  
      return $this;
  }
  
  /**
   * A visual identifier that represents this user.
   *
   * @see UserInterface
   */
  public function getUsername()
  {
      return (string) $this-&gt;email;
  }
  
  public function getRoles(): ?array
  {
      return $this-&gt;roles;
  }
  
  public function setRoles(array $roles): self
  {
      $this-&gt;roles = $roles;
  
      return $this;
  }
  
  public function getPassword()
  {
      return $this-&gt;password;
  }
  
  public function setPassword($password): self
  {
      $this-&gt;password = $password;
  
      return $this;
  }
  
  /**
   * @see UserInterface
   */
  public function getSalt()
  {
      // not needed when using the "bcrypt" algorithm in security.yaml
  }
  
  /**
   * @see UserInterface
   */
  public function eraseCredentials()
  {
      // If you store any temporary, sensitive data on the user, clear it here
      // $this-&gt;plainPassword = null;
  }
  
  public function getFirstName()
  {
      return $this-&gt;firstName;
  }
  
  public function setFirstName( $firstName): self
  {
      $this-&gt;firstName = $firstName;
  
      return $this;
  }
  
  public function getLastName()
  {
      return $this-&gt;lastName;
  }
  
  public function setLastName( $lastName): self
  {
      $this-&gt;lastName = $lastName;
  
      return $this;
  }
  
  public function getImage(): ?string
  {
      return $this-&gt;image;
  }
  
  public function setImage(string $image): self
  {
      $this-&gt;image = $image;
  
      return $this;
  }
  
  public function getAddress()
  {
      return $this-&gt;address;
  }
  
  public function setAddress( $address): self
  {
      $this-&gt;address = $address;
  
      return $this;
  }
  
  public function getIdNumber()
  {
      return $this-&gt;idNumber;
  }
  
  public function setIdNumber( $idNumber): self
  {
      $this-&gt;idNumber = $idNumber;
  
      return $this;
  }
  
  public function getPhoneNumber()
  {
      return $this-&gt;phoneNumber;
  }
  
  public function setPhoneNumber( $phoneNumber): self
  {
      $this-&gt;phoneNumber = $phoneNumber;
  
      return $this;
  }
  
  /**
   * @return Collection|Vehicle[]
   */
  public function getVehicle(): Collection
  {
      return $this-&gt;vehicle;
  }
  
  public function addVehicle(Vehicle $vehicle): self
  {
      if (!$this-&gt;vehicle-&gt;contains($vehicle)) {
          $this-&gt;vehicle[] = $vehicle;
          $vehicle-&gt;setUser($this);
      }
  
      return $this;
  }
  
  public function removeVehicle(Vehicle $vehicle): self
  {
      if ($this-&gt;vehicle-&gt;contains($vehicle)) {
          $this-&gt;vehicle-&gt;removeElement($vehicle);
          // set the owning side to null (unless already changed)
          if ($vehicle-&gt;getUser() === $this) {
              $vehicle-&gt;setUser(null);
          }
      }
  
      return $this;
  }
  
  public function getAccount(): ?Account
  {
      return $this-&gt;account;
  }
  
  public function setAccount(?Account $account): self
  {
      $this-&gt;account = $account;
  
      return $this;
  }
  </code></pre>
  
  <p>}</p>