processing / p5.js-web-editor

The p5.js Editor is a website for creating p5.js sketches, with a focus on making coding accessible and inclusive for artists, designers, educators, beginners, and anyone else! You can create, share, or remix p5.js sketches without needing to download or configure anything.
https://editor.p5js.org
GNU Lesser General Public License v2.1
1.3k stars 1.26k forks source link

Logged out error modal pops up when downloading another user's sketch #3053

Closed lindapaiste closed 1 month ago

lindapaiste commented 4 months ago

p5.js version

No response

What is your operating system?

None

Web browser and version

No response

Actual Behavior

image

Expected Behavior

I should be able to download p5's sketch without any error.

The sketch actually does export successfully, using the saved version of the project.

We are getting this message because we make a PUT request to the API before exporting a sketch. That API request will fail if the user is not the owner of the sketch. The easiest solution would be to only make that API call if there is a logged in user and that user is the owner of the sketch.

The relevant code is here: https://github.com/processing/p5.js-web-editor/blob/64c36cae65541783e848eb5c0e11eb255ec6c940/client/modules/IDE/hooks/useSketchActions.js#L42-L45

There is some nuance here with regards to how we would handle local/unsaved changes. Right now those changes would not be applied if it is not your sketch. This is part of a larger discussion happening in #2904.

Steps to reproduce

Steps:

  1. Make sure that you are logged out
  2. Go to a sketch which is not your own, such as https://editor.p5js.org/p5/sketches/Data:_True_and_False
  3. Click the "File" menu
  4. Click "Download"
vivekbopaliya commented 4 months ago

I haven't looked into the issue yet but why are we calling autoSaveProject before downloading? It doesn't seem necessary to save someone's project before downloading it i think so. Removing that step should fix it.