Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken" is not a valid entity or mapped super class. #333

Open
LambertHumans opened this issue Jul 21, 2022 · 4 comments

Comments

@LambertHumans
Copy link

Hi everyone,
I just installed Gesdinet JWT refresh token, but can't make it works. I'm facing this error :

Class "App\Entity\RefreshToken" sub class of "Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken" is not a valid entity or mapped super class.

I didn't made any change on bundle configuration, I only replaced refresh token route.
I'm using Sf6 with postgresql and php8.1.

Do you guys have an idea on how I can solve this ?

Thank you !

@Lugh-Web
Copy link

Hello

I have exactly the same problem.

I tried following these instructions:
#332

But the result is the same.

I'm on SF 6 and PHP 8

In the documentation we have to update our database with the new RefreshToken entity and absolutely nothing happens even when forcing the update.

@Lugh-Web
Copy link

Lugh-Web commented Jul 21, 2022

@LambertHumans after looking a second time the Following procedure :
#332

I have change the entity and It works now


<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;

#[ORM\Entity]
#[ORM\Table(name: 'refresh_token')]
class RefreshToken extends BaseRefreshToken
{
    public function getId() 
    {
        return $this->id;
    }
}

@justingivens
Copy link

@Lugh-Web, thanks for dropping this in! This also fixed my issue.

@vesirem
Copy link

vesirem commented Jun 16, 2023

I've been struggling for a while to set up this refresh token using SF 6.2 + API platform 3.1 using PHP8.2

It looks like there are conflicts between annotations and attributes, and that the RefreshTokenRepository cannot be reached inside the vendor directory.

I searched on the web for similar issues, found several in 2022 but nothing really recent.

Anyway I finally made it work by modifying the RefreshToken.php and placing the RefreshTokenRepository inside the project Repository folder.
These are the only differences I implemented vs this documentation.

Here is the adjusted Entity

namespace App\Entity\Main;

use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;

#[ORM\Table(name: 'refresh_token')]
#[ORM\Entity(repositoryClass: 'App\Repository\Main\RefreshTokenRepository')]
class RefreshToken extends BaseRefreshToken
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    protected $id;

    #[ORM\Column(type: 'string')]
    protected $refreshToken;

    #[ORM\Column(type: 'string')]
    protected $username;

    #[ORM\Column(type: 'datetime')]
    protected $valid;
}

And the Repository simply copied from the vendor dir and pasted in the project

namespace App\Repository\Main;

use Doctrine\ORM\EntityRepository;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenRepositoryInterface;

/**
 * @extends EntityRepository<RefreshToken>
 * @implements RefreshTokenRepositoryInterface<RefreshToken>
 */
class RefreshTokenRepository extends EntityRepository implements RefreshTokenRepositoryInterface
{
    /**
     * @param \DateTimeInterface|null $datetime
     *
     * @return RefreshToken[]
     */
    public function findInvalid($datetime = null)
    {
        $datetime = (null === $datetime) ? new \DateTime() : $datetime;

        return $this->createQueryBuilder('u')
            ->where('u.valid < :datetime')
            ->setParameter(':datetime', $datetime)
            ->getQuery()
            ->getResult();
    }
}

Hope this will help others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants