Where to store some important data fetched from API so that I can use it in multiple routes?
Mayur Aitavadekar
Posted on July 9, 2020
I am developing OTP authentication. So here my routes in express -
const express = require("express");
const router = require("express").Router();
const rp = require("request-response");
router.post("/sendOTP", (req, res) => {
const { mobile_number } = req.body; // receive the mobile number
const otp = randomize("0000"); // generated 4 digit otp
options = {
method: "GET",
url: "xxxxx/xxxxx/xxxxx/${otp}", // calling my otp service provider to send otp to my user
}
rp(options).then((response)=>{
// response.details contains the unique otp session id which I have to use in another route where I am verifying otp
}).catch((err) => console.log(err));
});
router.post("/getOTP", (req, res) => {
// user will put otp he received from his mobile
const { otp } = req.body; // receive the otp
options = {
method: "GET",
url: "xxxxx/xxxxx/xxxxx/${otp}/${otp_session_id}", // calling my otp service provider with otp and session id of otp
}
rp(options).then((response)=>{
console.log(response) // otp verified.
}).catch((err) => console.log(err));
});
this is simple code. Now my problem is - how can I store that otp_session_id so that I can use it in two routes sendOTP
and getOTP
? I used cookieParser, cookieSession, expressSession, nothing worked out. please any simple steps / solutions will be great.
thanks :)
💖 💪 🙅 🚩
Mayur Aitavadekar
Posted on July 9, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
privacy Caught in the Crunch My Journey from Snacks to 2 Million Exposed Users Privacy
November 30, 2024
devchallenge Submission for the DevCycle Feature Flag Challenge: Feature Flag Funhouse
November 30, 2024