Nodejs guest login question?

I want to guest user in my app, and I try to make separate route with pre defined user this is already stored in my db and I authenticate user with passport, but the problem I saw in this approach is then I am force to implement passport.authenticate function again but I already implement it in login route something like this. Is any better way to implement guest functionally in my webapp?

const guestCreadentials = req.body;
        const user = await userModel.findOne({ email: guestCreadentials.email, username: guestCreadentials.username })
        if (!user) return res.status(404).send({
            failure: true,
            msg: "This is server error!"
        })
        const login_user = { email: guestCreadentials.email, password: guestCreadentials.password }
        console.log("saved user: ", login_user)
        passport.authenticate('local', (err, user, info) => {
            if (err) next(err);
            if (!user) return res.status(404).send("User not found")
            req.logIn(user, function (err) {
                if (err) { return next(err); }
                return res.send(user);
            });
        })(req, res, next)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.