iron-session icon indicating copy to clipboard operation
iron-session copied to clipboard

req.session.user is throwing ts error

Open AimanAlmureish opened this issue 2 years ago • 1 comments

Hello! First of all the library really amazing.

Second I am using Next with Prisma and whenever I try to assign user to req.session I get this error

Property 'user' does not exist on type 'IronSession'.ts(2339)

So I opened index.d.ts where session type is defined and had to change its type from this

interface IncomingMessage { session: IronSession; }

to this

interface IncomingMessage { session: any; }

And it worked! But if there is any other solution can you provide it please and thank you so much.

AimanAlmureish avatar Jul 04 '22 12:07 AimanAlmureish

This is how you can define custom properties: https://github.com/vvo/iron-session/blob/a6c767d425c52575f743e86b64b8b4a4ce64add6/examples/next.js-typescript/lib/session.ts#L13-L18

jasonappah avatar Jul 04 '22 23:07 jasonappah