'Symfony 5 Heroku Unable to create a signed JWT from the given configuration

So, I have deployed a JWT project in Heroku and I get following error

 Uncaught PHP Exception Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTEncodeFailureException: "Unable to create a signed JWT from the given configuration." at /app/vendor/lexik/jwt-authentication-bundle/Encoder/LcobucciJWTEncoder.php line 38

.env

APP_ENV=prod
APP_SECRET=4b3623b38e2d6ba78fe9vdfx59dc3dd5
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=pass
DATABASE_URL="sqlite:///%kernel.project_dir%/var/task.db"

In git cmd I also did, but didn't worked.

heroku config:set APP_ENV=prod
heroku config:set JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
etc

In localhost it is working well JWT Token is generating fine but in heroku I get above error.



Solution 1:[1]

if you used lexit have you thought of regenerating your private and public keys on your production environnement?

php bin/console lexik:jwt:generate-keypair    

Solution 2:[2]

I had the same issue recently and as @php-abs metioned, I just added it to the composer.json file in the scripts/auto-scripts section as a command as shown bellow:

"scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd",
            "lexik:jwt:generate-keypair": "symfony-cmd"
        },
...
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AnthoBS
Solution 2 Abdelilah Aassou