Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.session.regenerate is not a function #181

Open
haydarai opened this issue Aug 4, 2022 · 17 comments
Open

req.session.regenerate is not a function #181

haydarai opened this issue Aug 4, 2022 · 17 comments

Comments

@haydarai
Copy link

haydarai commented Aug 4, 2022

It seems to be because of this jaredhanson/passport#907, probably a good idea to downgrade the passport version for now.

@younes-io
Copy link

@rkusa : can you please downgrade ? This is really blocking me and I'm rethinking to switch to express if this is going to take a long time :/

@rkusa
Copy link
Owner

rkusa commented Aug 11, 2022

@younes-io @haydarai Sole purpose of koa-passport 5.x was to upgrade passport to v6. So if you have to use an older version of passport, you can use koa-passport 4.x for now.

@nemphys
Copy link

nemphys commented Aug 21, 2022

@rkusa koa-passport 5 uses passport v6 whereas koa-passport 4 uses passport v4. Since passport v5 seems to be the way to go for now, how does one handle that?

@rkusa
Copy link
Owner

rkusa commented Sep 4, 2022

@nemphys Fair point. Passport v5 looks to me like it just stops extending http.IncomingMessage.prototype, which koa-passport already did from the begining (and all other minor releases are about fixes/compatibility for that change). However, I might be wrong. In this case, you could depend on koa-passport@4 and pin passport to v5 - the combination should work fine I think.

@nemphys
Copy link

nemphys commented Sep 8, 2022

@rkusa right, this is doable, but I just realised that it beats my purpose to get rid of the passport < 0.6.0 vulnerability (which is the reason I wan to update koa-passport :-) )

@CherryDT
Copy link

CherryDT commented Oct 8, 2022

Is there any ETA for this? I'm considering my options for what the best way would be to solve this problem within the next few weeks (waiting for a fix or refactoring)

@lehni
Copy link
Contributor

lehni commented Oct 31, 2022

@rkusa passport is defined as a dependency of koa-passport, not a peer dependency. So when using koa-passport@4, passport@0.4 will be used, not v0.5. Also, please note that all passport versions starts with 0., this is currently wrong in the README which speaks of v5 and v6, etc. See https://github.com/jaredhanson/passport/tags

davidnbooth pushed a commit to davidnbooth/koa-passport that referenced this issue Nov 23, 2022
Add dummy req.session.regenerate and req.session.save for passport 0.6.0
davidnbooth pushed a commit to davidnbooth/koa-passport that referenced this issue Nov 24, 2022
Only add dummy regenerate and save methods if they do not already exist
@lehni
Copy link
Contributor

lehni commented Dec 5, 2022

I've added a fix to koa-session with which I am able to use koa-passport correctly, see: koajs/session#221

@rkusa
Copy link
Owner

rkusa commented Dec 6, 2022

I am contemplating whether I should merge #187 (add a workaround to koa-passport) or point everyone to a custom middleware as a workaround (see #187 (comment)). Any opinions?

@nemphys
Copy link

nemphys commented Dec 6, 2022

@rkusa I suppose the 2nd option is better; merging something like that in koa-passport would just be an ugly fix, so anyone interested (including myself) should take the responsibility of adding it to the codebase.

@lehni
Copy link
Contributor

lehni commented Feb 4, 2023

koa-session v6.4.0 was just released, with my PR linked above merged (koajs/session#221). This solves the issue without any workarounds needed.

@nemphys
Copy link

nemphys commented Feb 4, 2023

Nice! What about koa-generic-session?

@lehni
Copy link
Contributor

lehni commented Feb 5, 2023

Perhaps the MR can serve as a scaffolding for the same change there? I don't use koa-generic-session, so won't have the time to look into it.

@ilonaand
Copy link

ilonaand commented Feb 7, 2023

"koa-passport": "^6.0.0",
"koa-router": "^12.0.0",
"koa-session": "^6.4.0",

We get error: 2023-02-07T12:19:47.935Z error: uncaughtException: Cannot read properties of null (reading 'regenerate')
TypeError: Cannot read properties of null (reading 'regenerate')
at C:\d\node_modules\passport\lib\sessionmanager.js:83:17
at C:\d\node_modules\koa-session\lib\session.js:156:26
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Please help, how to fix that?

@lehni
Copy link
Contributor

lehni commented Feb 7, 2023

@ilonaand the failing line of code is here:

req.session.regenerate(...)

https://github.com/jaredhanson/passport/blob/72119401792ddda24e7c2b652d8d3e2decdbee5d/lib/sessionmanager.js#L83

So it looks like you don't have a session. Are you sure you're actually using the koa-session plugin?

@ilonaand
Copy link

ilonaand commented Feb 7, 2023

Thanks, but we using koa-session

import session from 'koa-session';
import passport from 'koa-passport';

passport.serializeUser((user: unknown, done) => {
log.info('serializeUser', user);
done(null, (user as IUser).id);
});

passport.deserializeUser((id: string, done) => {
try {
log.info('deserializeUser', id);
const user = userService.findOne(id);
done(null, user);
} catch (err) {
done(err);
}
});

.use(session(Config, app))
.use(passport.initialize())
.use(passport.session())

The user logs in without errors, the session is created, and the error occurs immediately after logging out

@lehni
Copy link
Contributor

lehni commented Feb 7, 2023

Very strange. We have a setup very similar to do this, and it all works for us. The error message does hint at req.session missing, so the problem lies somewhere there.

erkannt added a commit to sciety/sciety that referenced this issue Feb 13, 2023
VINXIS added a commit to Corsace/corsace that referenced this issue Jul 2, 2023
* initial team model and stuff

* a few team endpoints, teams discordcmd, refresh token functionality

* update migration

* ok i made all the team endpoints

* npm run audit

* update migration

* mode ID filters for bws

* fix build

* discord commands and restructure db function locations

* rename save to upload

* test fixes

* more fixes and add public folder

* no support for gifs (yet)

* more fixes and also better image cropping

* more fixes, more discord cmds, create getTeamInvites

* change team ava url to explicit api url due to proxy

* ok 10 mb kinda ridiculous

* extra security (dont use discord ID lookup), more test fixes

* tournament registration cron

* cron fixes

* ease on cron queries

* fix missing inv accept check + rewrite for loop

* optimize discord invite q (and support actionRow limit)

* use r2 for team avatars

* feat: add base for osu irc bot (#208)

* feat: add base for osu irc bot

* fix: connection log typo

* style: simplify self-message check

* feat: add botAccount boolean

* style: whitespace

* feat: multiplayer commands, listen to channel message event

* style: remove unnecessary parentheses

* fix: placement of parentheses

* feat: reduce command handler duplication

* fix: whitespace

* fix: more whitespace

* Match Infrastructure (#207)

* initial match model creation

* initial match migration and models and routing

* pickban order(maporder) entity

* additional properties for match specs + update migration + change match name (sql reserved keyword)

* remove discriminators in discord + errors

* rename match to matchup everywhere

* matchup generator endpoint (remove stages)

* fix migration also add a first property

* npm run lintfix

* update readme for ircbot

* intiial cron setup

* add matchupGroup to models for qualis

* feat: require a qualifier date when a team registers for a tournament with a qualifier stage (#211)

* feat: require a qualifier date on team register if tourney has qualifiers, create matchup

* fix: wtf

* Auto-running Qualifiers (#213)

* renaming irc to bancho

* more bancho renaming

* some pool check fixes for create/publish

* Create match creation logic stuff

* model + migration fixes

* missing checks on slot map count

* finish initial setup for auto-running qualifier

* 🚑 ⬆️ Upgrade nodesu and bancho.js, fixing typings compilation (#214)

* import osu bot

* fixes to miscellaneous stuff + build

* finish qualis bot

* add missing leftjoin in register endpoint

* more refbot fixes

* change cron delay to 10 seconds

* more fixes and also actually make the timers matter

* check all players in lobby before running autostart

* final fixes before i lose my mind refactoring

* REFACTOR!!!!!

* poon fixes

* nicer log storage Yey

* fix matchup running in cron-runner instead of bancho (+ dupe bancho client instances)

* mod function fix

* wrote wrong publicurl name in docker-compose.json

* actually end match

* remove unnecessary saves keep matchup save for match end

* poon suggestion

* Bancho Message Storage (#215)

* matchupmessages model and migration

* add matchupmessage logic to ref bot

* testing

* batch save and clear timer on end

* date save

---------

Co-authored-by: Hugo Denizart <thepoon@osufr.live>

* update koa-session to circumvent koa-passport 6 issues rkusa/koa-passport#181

* fixes and refactors to osu apiv2

* add typing to badgefilter

* annoying build fixes and mode type

---------

Co-authored-by: James <tsunyoku@gmail.com>
Co-authored-by: Hugo Denizart <thepoon@osufr.live>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants