Hi Scott,

Sorry about this. I reviewed the doc on "eval" and it's working now.

        eval {my $status = $jwt->decode($token);};
        return 0 if $@;
        return $status;

On Wednesday, 23 May 2018 13:23:54 UTC-4, Luc Larochelle wrote:
>
> Hi Scott,
>
> I tried this and it would still die. Can you provide a snippet ? I've used 
> eval only once, based on code example I was working on.
>
> On Friday, 18 May 2018 16:58:02 UTC-4, Scott Wiersdorf wrote:
>>
>> Mojo::JWT::decode can die, so you'll want to wrap that in an eval() and 
>> trap the exception.
>>
>> Scott
>>
>> On Friday, May 18, 2018 at 1:57:11 PM UTC-6, Luc Larochelle wrote:
>>>
>>> I'm using Mojo::JWT to produde a token and verify authorization on 
>>> routes (using the given token, with the same secret)
>>>
>>> Thing is , when the token is invalid, an error is being thrown and the 
>>> application crashes. I'd like to contain the error and deal with it.
>>>
>>> What am I missing ? Here's the sample code
>>>
>>>
>>>
>>> use Mojo::JWT;
>>> use Mojolicious::Lite;
>>> use Data::Dumper;
>>>
>>> helper check_token => sub  {
>>>
>>>         my $self = shift;
>>>         my $token = $self->req->headers->authorization;
>>>         my $jwt = Mojo::JWT->new(secret => 'mytest');
>>>         return $jwt->decode($token);
>>>
>>> };
>>>
>>> any '/auth' => sub {
>>>         my $c = shift;
>>>         my $claims = $c->check_token;
>>>
>>>         if (!($claims)) {
>>>                 $c->render(json => {status => "error", data => { message 
>>> => "Please authenticate" }});
>>>         } else {
>>>                 $c->render(json => $claims);
>>>         }
>>>
>>> };
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to