Bargain23
Bargain23

Reputation: 1973

Express - How do I pass data to the model without using query string parameters

So, I have two controllers, authController and onboardingController. authController communicates with onboardingController with this line:

res.redirect('/onboarding/info?profileId=' + profile.id + '&emailAddress=' + profile.emails[0].value)

onBoardingController receives the query string parameters and transforms them into metadata that is accessible when rendering the corresponding page:

model.profile = { id: req.query.profileId, email: req.query.emailAddress };
res.render('onboarding/missingInfo', model);

Now, since model.profile in onboardingController doesn't know the context behind the actual profile data from the authController, I only thought of passing and receiving data through query strings. Is there any other way I can do this because having an email address in the URL makes it look wonky.

Edit: I've read that it's possible to use express sessions to do what I need.

Upvotes: 0

Views: 33

Answers (1)

SirPeople
SirPeople

Reputation: 4348

You could create a POST request and send it in the body of the request (using axios, or the Fetch API).

Nice article of W3Schools about it

Upvotes: 1

Related Questions