mattmilburn / strapi-plugin-preview-button

A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view.
MIT License
100 stars 35 forks source link

How to add secret token? #96

Open bnsx opened 1 year ago

bnsx commented 1 year ago

http://localhost/preview?type=article&slug=game&secret=JWT_TOKEN_HERE

When i config jwt in config/plugins.js isn't work

I mean jwt token will generate 1 time not every time

expected : i want jwt token generate every time when i open link.

kristijorgji commented 1 year ago

did you try to execute a function there someUrl&secret=generateSecret()

kristijorgji commented 1 year ago

You can create one endpoint and call it to generate a real-time secret, thats what i did

tapornanan commented 1 year ago

@kristijorgji How about if I want to pass some identifier(id) to the generateSecret()?

kristijorgji commented 12 months ago

@tapornanan I did exactly this and works fantastic.

Create one api endpoint and call it in the build preview url hook by sending all the entity data. Then you can use the id while creating the secret every time you create the preview url.

It works great, it also means that you make 2 api calls every time you open a content that is in draft mode to generate the preview url.