Help getting the dynamic value of a cookie and passing it to a plugin

Hello folks,

I definitely can use some help building my first server side plugin once that I’ve being trying to debug my code for a while now.

I’m building a simple plugin to read a jwt cookie containing user information such as id, username and email and set those attributes as custom states in my page (Images 1 - 3).

My plugin uses two fields: jwt and secret. The plugin works fine when the jwt field is a static string. Nevertheless, when I try to pull the jwt string dynamically from the cookie it does not “appear” in the plugin - even though the plugin evaluates the field correctly (image 4) - and I get an empty jwt value that breaks the code when the jsonwebtoken package tries to run the verify function (Image 5).

Can anybody help me understand what I am missing or suggest a different approach to the task?

Thanks!

IMAGE 1:

IMAGE 2:

IMAGE 3:

IMAGE 4:

IMAGE 5:

Well, you’ve got a stray comma in your return. You mean to do this:

return { decodedToken: result }

2 Likes

The error is clear, the plugin does not get the jwt. The problem is in the workflow editor: you assume every step runs one after each other but clearly the request to the plugin triggers before the cookie value is available. You can read in the manual the base rules for order of execution for workflows.
Is the get cookie a client-side plugin action that publishes a state of the element? If yes then you need to trigger an event right after the state is published and run any logic that depends on that state in another workflow triggered by the event so that you can be sure to have the data.

1 Like

I guess you’re right!

I’m studing how to implement your solution.

Thanks dorilama.

1 Like