-
Notifications
You must be signed in to change notification settings - Fork 465
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
TypeError: Cannot set property 'userId' of undefined #57
Comments
If you hover into the session from request object, you'll get:
The default Session object isn't able to add out custom fields like UserId. My take was to do declaration merging by: "typeRoots": [
"./src/types", // for express.session declaration merging
"./node_modules/@types"
] And adding this in the types.ts: import "express-session";
declare module 'express-session' {
export interface Session {
userId: number;
}
}
export type myContext = {
em: EntityManager<IDatabaseDriver<Connection>>;
req: Request & { session: Session & Partial<SessionData> };
res: Response;
} Also, see check the secure property in the cookie property of app.use(session(...)). I had to set it to false to make the cookie work. Hope this helps. |
I first solve this problem with @akumaaayush's approach, and then, I found an issue that is all about this problem, so I came to share it. |
@akumaaayush @ryankert01 thank you for your help but I have tried all this plus everything in #13 and I am still getting the same error. |
Hi Ben,
Thank you so much for this tutorial.
If any one can help me I would really appreciate it
I have been stuck on this part for over two days. Any time I add in line 141 I get the error below in my sandbox . I have also added in a screen shot from my types file. I also do not see any cookie being set. I f I remove line 141 I do not get an error it logs me in but still does not set a cookie.
Thanks for any help!
)
The text was updated successfully, but these errors were encountered: