Skip to content

x.vweb: add new sessions module - #20642

Merged
spytheman merged 10 commits into
vlang:masterfrom
Casper64:sessions
Feb 7, 2024
Merged

spytheman merged 10 commits into
vlang:masterfrom
Casper64:sessions

Conversation

@Casper64

Copy link
Copy Markdown
Contributor

Add new sessions module for x.vweb.

The main goal of this session module is to provide a way of using sessions easily with vweb while also making it usable outside vweb.

Documentation is inside the README file.
Tests are also included.

Stores

The session store handles the saving, storing and retrieving of data. There are currently two implementations:

  1. The MemoryStore[T] stores session data in memory only using the map datatype.
  2. The DBStore[T] stores session data in a database by encoding the session data to JSON.

It is possible to create your own implementation of a session store. You only need to follow the Store interface. See "Custom Stores" in the README.

Usage

This module provides a Sessions struct which the user can embed in their vweb app. It makes the usage of sessions easier, for example session data is retrieved automatically when the provided middleware is used. The struct stores session id's in a cookie and you can use any session store.

See the Usage section in the README file for more information and on how to use this module outside vweb, or without the Sessions struct.

Comment thread vlib/x/vweb/sessions/README.md
Comment thread vlib/x/vweb/sessions/db_store.v
Comment thread vlib/x/vweb/sessions/tests/db_store_test.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v
Comment thread vlib/x/vweb/sessions/sessions.v
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
Comment thread vlib/x/vweb/sessions/db_store.v Outdated
Comment thread vlib/x/vweb/sessions/db_store.v
Comment thread vlib/x/vweb/sessions/sessions.v Outdated
@spytheman
spytheman marked this pull request as draft February 3, 2024 11:17
@Casper64
Casper64 marked this pull request as ready for review February 6, 2024 21:19

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work πŸš€ .

@spytheman
spytheman merged commit 3bd9930 into vlang:master Feb 7, 2024
@Casper64
Casper64 deleted the sessions branch February 7, 2024 21:20
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 this pull request may close these issues.

4 participants