in reply to Dancer2 JWT with multiple apps isn't working

First of all, put use strict; in use.

I'm not using Dancer, but it seems that you should use jwt() instead of bare jwt. And try to get plugin code from your $app reference, it seems more accurate and safe:

package Util { use Dancer2; use Dancer2::Plugin::JWT; sub before_request { my $app = shift; my $jwt_plugin = $app->find_plugin('Dancer2::Plugin::JWT') or $app->dsl->send_error('Could not find JWT plugin'); my $jwt = $jwt_plugin->jwt(); print "BEFORE REQUEST WORKED: " . $app->name . " " . $jwt . "\n"; } };

More of how to use Dancer plugins read in documentation Dancer2::Plugin.

Replies are listed 'Best First'.
Re^2: Dancer2 JWT with multiple apps isn't working
by clemep8 (Acolyte) on Jan 03, 2021 at 19:36 UTC
    Thanks, this suggestion was actually already made by the JWT maintainer (ambs) in github:
    my $jwt_plugin = $app->with_plugin('Dancer2::Plugin::JWT'); my $jwt = $jwt_plugin->jwt();
    and, as you suggest, this:
    my $jwt_plugin = $app->find_plugin('Dancer2::Plugin::JWT'); my $jwt = $jwt_plugin->jwt();
    seems to work also.