How to temporarily save form data then force registration/login node.js/express

Viewed 18

I want to allow someone to fill out a form without being logged in but then ask for registration/login if they want to save the data. If I use middleware to check this how do I hold on to the information they've filled in before saving the record?

Below is my post request at present

app.post('/running', urlencodedParser, async (req, res) => {

    const plan = new planHeader({
        title: req.body.title,
        startDate: req.body.planHeader.startDate,
        targetdate: req.body.planHeader.targetdate,
        planlength: req.body.planHeader.planlength,
        creator: req.user._id
    });

    await plan.save();

    res.redirect(`/running/${plan._id}`)
})
1 Answers

Thanks to Ogoh.cyril and MTN. I took their advice and saved form to localStorage if user isn't logged in. I then take them through registration and populate form again based on their localStorage then they're able to save.

Related