solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
4.93k stars 371 forks source link

[Bug?]: Session "spreads" the userId string into session.data #1536

Closed ile closed 1 week ago

ile commented 2 weeks ago

Duplicates

Latest version

Current behavior 😯

Using a solid-start app, template app which has sessions enabled, after logging in and doing console.log(session), I get this:

session {
  id: '4a4e5d74-2a7b-41b1-b2bd-936c7cbc3bd8',
  createdAt: 1718058677216,
  data: {
    '0': 'e',
    '1': '8',
    '2': 'b',
    '3': '6',
    '4': '3',
    '5': '9',
    '6': '9',
    '7': '0',
    '8': '-',
    '9': '9',
    '10': 'd',
    '11': '0',
    '12': 'c',
    '13': '-',
    '14': '4',
    '15': 'c',
    '16': 'e',
    '17': '5',
    '18': '-',
    '19': '8',
    '20': '2',
    '21': '6',
    '22': '8',
    '23': '-',
    '24': 'b',
    '25': '7',
    '26': 'c',
    '27': 'f',
    '28': 'a',
    '29': 'c',
    '30': '3',
    '31': '0',
    '32': '7',
    '33': 'e',
    '34': '7',
    '35': '3',
    userId: 'e8b63990-9d0c-4ce5-8268-b7cfac307e73'
  }
}

So it sets/assigns this userId string into the session data object by some method, which "spreads" it into the object. Probably something like Object.assign(session.data, userId);.

Expected behavior 🤔

Should not create this kind of object.

Steps to reproduce 🕹

Steps:

  1. Install a solidstart template app
  2. log in
  3. do a console.log()

Context 🔦

No response

Your environment 🌎

No response

ryansolid commented 2 weeks ago

Honestly I'm not sure. We don't do this to my knowledge. We only use the API's provided by H3 here as pure re-export. Maybe this is H3 behavior?

ile commented 2 weeks ago

I suspect it's H3 behavior.

Brendonovich commented 2 weeks ago

h3 assigns the result of the update function to the session itself

image

The assignment expression is returning user.id from the function and that's ending up in Object.assign

image

Just need to wrap the update functions in braces