Swirh
Swirh

Reputation: 1

Location to save api token?

I'm not sure which is gonna be the best location to save API key which users generating by providing email address and password, right now I'm finding temporary direction on their machine and saving it there.

But I'm not sure if it is the best approach.

Notes:

API key has to be regenerated every 6 or 12 hours (depends).

I can't save it in the cache memory, because API endpoint which returning API key for another endpoint (which requires email and password) is rate-limited by 5 requests a day.

Upvotes: 0

Views: 547

Answers (2)

Alator
Alator

Reputation: 508

You could use local storage.

See https://www.w3schools.com/html/html5_webstorage.asp

Upvotes: 0

Rahul Shukla
Rahul Shukla

Reputation: 8065

You have to create an express-session: https://www.npmjs.com/package/express-sessions

Store Session:

let session = require("express-session");

app.use(session({
    secret: "secret",
    resave: false,
    saveUninitialized: true,
    cookie: {secure: true,
        httpOnly: true,
        maxAge: 1000 * 60 * 60 * 24
    }
}));

Use:

router.route("/login")
    .post(function(req, res) {

        req.session.Auth = req.body.user // => user values?
    })

Upvotes: 1

Related Questions