Skip to content
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

Get session ID from header instead of cookie #292

Open
2 tasks done
Levyks opened this issue Jan 23, 2025 · 1 comment · May be fixed by #293
Open
2 tasks done

Get session ID from header instead of cookie #292

Levyks opened this issue Jan 23, 2025 · 1 comment · May be fixed by #293

Comments

@Levyks
Copy link

Levyks commented Jan 23, 2025

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

As the title say, a way to allow for other ways to retrieve the session id from the client (and also send it back), maybe not only with headers, but creating a interface that the user could implement any custom logic to it.

Motivation

I would like to use sessions to store data in my API, accessing it from places that are not a browser, where handling cookies are not as convenient as just a plain header

Example

app.register(fastifySession, {
  secret: 'a secret with minimum length of 32 characters',
  // Maybe you guys have a better name suggestion for this parameter
  sessionId: {
    retrieve(request, cookieOptions) {
      return request.headers['session-id'];
    },
    set(reply, sessionId, cookieOptions) {
      reply.headers('session-id', sessionId);
    }
  } 
});
@Levyks Levyks linked a pull request Jan 23, 2025 that will close this issue
4 tasks
@Levyks
Copy link
Author

Levyks commented Jan 23, 2025

I've created a PR to test the concept, I'm not sure if idStore is the best suited name for it, but it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant