jaredhanson / jaredhanson/connect-flash
res.redirect happening before req.flash
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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