storyblok / custom-app-examples

https://custom-app-examples.vercel.app
5 stars 1 forks source link

last_author may be null in a story object #21

Closed kynda-matthijs closed 1 year ago

kynda-matthijs commented 1 year ago

If we try to get this code working on a clean just created space, all works fine except for the fact thet get fetch stories call seems to return no results. This is unexpected since the default space contains one story with the name 'home'. After some debugging it became clear that this story does NOT have a last_author. So this line

https://github.com/storyblok/custom-app-examples/blob/4f669d7312913a94d864a71ff45886e9a9c4d386/app-nextjs-starter/src/Story.ts#L16C3-L16C17

will discard this as not correct therefore the isStory call also fails and the isStories call will also fail for all arrays that contain this default home story object.

This is confusing for a developer starting with plugin dev.

Since all manually made stories do have a valid last_author field, the best solution would be to tp make the default space initialized with stories that gave some fake last_author with a friendly_name of e.g. "J. Doe" so this code will not break here.

If it is more common to have stories without a last_author (e.g. after importing using the management API), it would be more appropriate to allow this code to work also on empty last_author fields.

demetriusfeijoo commented 1 year ago

Thank you for reporting it so clearly, @kynda-matthijs.

Really appreciated it 🙌

I'm going to take a look at that and fix it as soon as possible.