routed_sessions
Routed adapter for server_sessions — framework-agnostic session runtime (Session, SessionStore, CookieStore, MemoryStore).
Wraps server_sessions for routed EngineContext.session (ctx.session, ctx.getSession/setSession, ctx.sessionId) and sessionMiddleware/RoutedSessionsProvider.
Install
dependencies:
routed: ^0.5.0
routed_core: ^0.5.0
routed_sessions: ^0.2.0
server_sessions: ^0.1.0
Routed's default session cookies are Secure, HttpOnly, and
SameSite=Lax. For local HTTP-only development, opt out explicitly on the
session configuration with secure: false; production deployments should
keep the secure default.
Usage
import 'package:routed_core/routed_core.dart';
import 'package:routed_sessions/routed_sessions.dart';
import 'package:server_sessions/server_sessions.dart';
void main() async {
final store = MemorySessionStore();
final engine = await Engine.create(
providers: [
...Engine.defaultProviders,
RoutedSessionsProvider(SessionConfig(store: store)),
],
);
engine.use(sessionMiddleware(store));
engine.get('/', (ctx) {
ctx.setSession('user', 'alice');
return ctx.json({'sessionId': ctx.sessionId, 'user': ctx.getSession('user')});
});
engine.get('/clear', (ctx) {
ctx.clearSession();
return ctx.json({'cleared': true});
});
await engine.serve(port: 8080);
}
See the runnable session example in the package's example/ directory.
Testing
dart test packages/routed_sessions
dart analyze --fatal-infos packages/routed_sessions/lib
Libraries
- routed_sessions
- Session middleware and
EngineContexthelpers for Routed applications.