Ouch, filesystem changes do indeed wipe the data, that's a hard lesson.
You were probably using an incompatible TWRP version.
Yes that procedure is correct. You can also flash the magisk apk in recovery, it's the same process as flashing the image.
Do refer to the guide posted here though.