keycloak / keycloak/keycloak-nodejs-connect
TypeError: Cannot read properties of undefined (reading "keycloak-token")
- Dominant language
- JavaScript
- Stars
- 740
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
Description:
While using the keycloak-connect middleware, I encountered the following error:
`TypeError: Cannot read properties of undefined (reading "keycloak-token").`
Error Stack:
```
TypeError: Cannot read properties of undefined(reading & #39; keycloak - token & #39;);
at SessionStore.get(/ path / to / project / node_modules / keycloak - connect / stores / session - store.js: 24 : 58);
at Keycloak.getGrant(/ path / to / project / node_modules / keycloak - connect / keycloak.js: 311 : 30);
at grantAttacher(/ path / to / project / node_modules / keycloak - connect / middleware / grant - attacher.js: 20 : 14);
at Layer.handle[as handle_request](/ path / to / project / node_modules / express / lib / router / layer.js: 95 : 5);
at trim_prefix(/ path / to / project / node_modules / express / lib / router / index.js: 328 : 13);
at / path / to / project / node_modules / express / lib / router / index.js: 286 : 9;
at Function.process_params(/ path / to / project / node_modules / express / lib / router / index.js: 346 : 12);
at next(/ path / to / project / node_modules / express / lib / router / index.js: 280 : 10);
at adminRequest(/ path / to / project / node_modules / keycloak - connect / middleware / admin.js: 119 : 16);
at Layer.handle[as handle_request](/ path / to / project / node_modules / express / lib / router / layer.js: 95 : 5)
```
### Version
26.1.1
### Expected behavior
The code should not throw the exception if `request.session` is undefined
### Actual behavior
The error TypeError: Cannot read properties of undefined (reading "keycloak-token") is thrown.
### How to Reproduce?
_No response_
### Anything else?
Environment Information:
Node.js Version: v22.9.0
Express Version: 4.21.2
Contributor guide
Research direction
Start at stores/session-store.js, specifically SessionStore.get, and inspect the request.session access shown in the stack trace. Read the related paths through middleware/grant-attacher.js and middleware/admin.js, then reproduce the undefined-session case with Node.js v22.9.0 and Express 4.21.2 if possible. Done means the case no longer throws the reported TypeError and has a focused regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, node.js
- Domain
- authentication, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100