//server.js
const csrf = require("csurf");
const csrfProtection = csrf({
cookie: true,
});
app.get("/api/csrf-token", csrfProtection, (req, res) => {
res.json({ csrfToken: req.csrfToken() });
});
app.post("/api/signup/stepTwo", csrfProtection, async (req, res) => {
try {
const savedCity = await knex("UserCity").insert([
{
Street: req.body.street,
City: req.body.city,
},
]);
if (savedCity) {
return res.json({
message: "Answers saved!",
});
} else {
return res.status(400).json({
message: "There was a problem saving your answers",
});
}
} catch (err) {
return res.status(400).json({
message: "There was a problem saving your answerst",
});
}
}
);
//stepOne - submit credentials
const submitCredentials = async (credentials) => {
//api call to submit credentials...
const router = useRouter();
useEffect(() => {
if (redirectOnLogin === true) {
router.push("/signup/stepTwo");
}
});
return (...
)
}
//stepTwo
const submitAnswers = async (answers) => {
try {
const { data } = await fetchContext.authAxios.post(
`signupStepTwo`,
answers
);
setTimeout(() => {
setRedirectOnLogin(true);
}, 700);
} catch (error) {
const { data } = error.response;
}
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…