I am trying to create a cookie every time a new user registers for my app, indicating that it is their first time logged in it. I have found this thread and roughly followed it but it isn't working.
Here is my current code:
// setting up the middle ware
export default function () {
return function () {
const app = this
app.use(cookieParser())
app.post('/app/signup/end', [firstTimeCookie(app), signUp(app)])
}
}
The middleware that isn't working is firstTimeCookie()
, signUp()
works fine.
// in firstTimeCookie:
export default function (app) {
return function (req, res, next) {
const cname = 'FIRST_SIGNUP'
const cvalue = true
var cookie = req.cookies.cookieName
if (!cookie) {
res.cookie(cname, cvalue, { maxAge: 1000 * 60 * 60 * 24 * 999999 })
} else {
console.log('cookie already exists')
}
next()
}
}
What am I doing wrong?