Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Is it by design that the session during the first server processing is not saved in storage? I'm guessing it's a bug. #89

Open
dogharrycatpotter opened this issue Sep 21, 2023 · 1 comment
Labels
question Further information is requested

Comments

@dogharrycatpotter
Copy link

Ask your question

The following conditions occur:

・There is a cookie that holds the session ID set in the HTTP request.
・The session on the server no longer exists on the storage
・Initial server access

During server processing, event.context.session.user = { name: 'abc' } is set to the session, but it is not saved on the server's storage.

The results of debugging index.mjs are below.

export default eventHandler(async (event) => {
  console.log(`@sidebase/nuxt-session eventHandler start`);
  await ensureSession(event);
  event.res.on("finish", async () => {
    const session = await getSession(event);
    console.log(`@sidebase/nuxt-session eventHandler end session`, session); // $1
    if (!session) {
      return;
    }
    await setStorageSession(session.id, event.context.session);
  });
});

The $1 comment line above is output as null, so it seems that the storage is not saved.

const getCurrentSessionId = (event) => {
  const sessionIdRequest = parseCookies(event).sessionId;
  const sessionIdContext = event.context.sessionId;
  console.log(`@sidebase/nuxt-session getCurrentSessionId sessionIdRequest`, sessionIdRequest); // $2
  console.log(`@sidebase/nuxt-session getCurrentSessionId sessionIdContext`, sessionIdContext); // $3
  if (sessionIdContext && sessionIdRequest && sessionIdContext !== sessionIdRequest) {
    return null;
  }
  return sessionIdRequest || sessionIdContext || null;
};

When I debug the getSession function, I see that the getCurrentSessionId function returns null.

The output content of the $2,3 comment line above is as follows.

@sidebase/nuxt-session getCurrentSessionId sessionIdRequest k2XJZcDXmKxtoAzbJIIM0sNr9piseVF1
@sidebase/nuxt-session getCurrentSessionId sessionIdContext nIHE9cPHVNaFwLtonucpZn6ANWVOS8F2

The version I'm using is below.
"@sidebase/nuxt-session": "^0.2.7"

Additional information

No response

@dogharrycatpotter dogharrycatpotter added the question Further information is requested label Sep 21, 2023
@agracia-foticos
Copy link

Same issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants