jaredhanson / jaredhanson/connect-flash

res.redirect happening before req.flash

Open
#23 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.2k
Forks
173
PR merge metrics
No merged PRs in 30d

Description

Hi

I am using express 4 and connect-mongo.

I have the following code in a route:

``` javascript
if (doc.pwdResetExpiration < new Date()) {
req.flash('error', 'Your recovery token has expired, please try again.');
return res.redirect('/account-recovery');
```

it can happen that the redirect is processed before the flash message in stored in the session (so it is never flashed to the user). It happens ~20% of the time

The output of console.log(req.flash()) in /account-recovery when repeatedly loading the above route :

```
{ error: [ 'Your recovery token has expired, please try again.' ] } ==> it flashed ok
{} ==> the flash was not stored in time
{ error: ==> it flashed ok again
[ 'Your recovery token has expired, please try again.',
'Your recovery token has expired, please try again.' ] }
```

Is there an easy way to make sure the flash message is stored before executing the redirect ?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the route shown in the issue with Express and connect-mongo, repeatedly following the redirect to /account-recovery. Inspect when the flash message is persisted relative to the redirect; done means the recovery message is consistently available after the redirect.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript
Domain
authentication, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.