Skip to content

Unify inconsistent api for manipulating session #34

@lokshunhung

Description

@lokshunhung

Prerequisites

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

🚀 Feature Proposal

Originally proposed by @SimenB, as quoted

[Add] methods on the session object itself rather than directly on the request object - today it has only regenerate and touch, but not save etc.. When using Express' session I never interacted with sessionStore directly, all methods (save, regenerate, reload, destroy) were all on the session object.

express fastify
request.session.reload(cb) request.sessionStore.get(request.session.sessionId, cb)
request.session.save({}, cb) request.sessionStore.set(request.session.sessionId, {}, cb)
request.session.regenerate(cb) request.session.regenerate() (no callback in fastify, unlike express)
request.session.destroy(cb) request.destroySession(cb)
request.session.touch() request.session.touch()
the methods for express also updates request.session - I guess calling the store directly doesn't do the same (that's probably a bug in my current migration at work).

If all methods are moved to request.session then I guess you can also choose not to expose sessionStore at all?

Motivation

The api to interact with session is very inconsistent.

Context here

Example

Instead of

request.sessionStore.get(request.session.sessionId, cb)
request.destroySession(cb)

We could do

await request.session.reload()
await request.session.destroy()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions