Comments (6)
Can you provide a minimal repro for your issue? It is more straight forward to debug or find out the problem with code.
Encapsulation is creating context base on .register
, folder structure do not affect the encapsulation.
I would recommend to register session
plugin globally, because it is hard to determine if you have any other routes / prefix need the session when your project growth.
from fastify-secure-session.
https://github.com/MyTotoro/ExampleFastifyApp
I've posted a minimal repo generated using fastify-cli
, hopefully you can easily reproduce what I'm seeing with a few commands:
npm install
npm run dev
the request.session
works fine with /auth/
and /auth/2
routes, you can see in the log that the session data is being stored and retrieved. What I expect is that this would work across other routes / inner folder structures. In places like /example
, I don't need the access to session
.
But as you said the folder structure might have no impact on this. Maybe I thought this would be similar to how fastify-cors
would be accessible to every route?
from fastify-secure-session.
As you are using fastify-autoload
, my statement about folder
is not correct. The folder structure do matter.
My advice would be split the protected and public routes into two app.js
.
For example:
// app.js
'use strict'
const path = require('path')
const AutoLoad = require('fastify-autoload')
const protected = require('./context/protected')
const public = require('./context/public')
module.exports = async function (fastify, opts) {
// plugins for global
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign({}, opts)
})
// register protected route with encapsulated context
fastify.register(protected)
// register public route
fastify.register(public)
}
// context/protected.js
module.exports = async function (fastify, opts) {
//
fastify.register(require('fastify-secure-session'))
// load protected routes only
}
// context/public.js
module.exports = async function (fastify, opts) {
// load public routes only
}
from fastify-secure-session.
what documentation describes how fastify-autoload
manages context? I'd like to properly understand whats happening
Thanks for the suggestion. I don't quite understand how registering fastify-secure-session
in context/protected
is different than my folder structure? Unless the fastify instance that is passed into context/protected
routes will have context properly populated with secure-session
?
from fastify-secure-session.
fastify-autoload
is a plugin to help you do .register
automatically. Unless you explicitly specified, each .register
should create a new encapsulate context.
I am against any starter using fastify-autoload
as it hide all the detail of how fastify
runs and how to deal with encapsulation.
from fastify-secure-session.
I see - I read more into the documentation of autoload
, I just moved the auth logic into a plugin and registered as a plugin across my app. Thanks for your help
from fastify-secure-session.
Related Issues (20)
- "k\" must be crypto_secretbox_KEYBYTES bytes long HOT 2
- `.bin` is not registered when using yarn HOT 6
- New cookie is made on every request, even if session is unchanged HOT 2
- Multiple cookies HOT 2
- v5.3.0 breaks with `Cannot read properties of undefined (reading 'sign')"` HOT 4
- Segmentation Fault when using alpine image HOT 7
- Enable multiple cookie sessions HOT 5
- Missing peer dependency on fastify HOT 8
- "No native build was found" HOT 3
- No native build was found - EsBuild AWS Lambda HOT 2
- Release new version to be type compatible with other `@fastify/cookie` modules HOT 1
- Update cookie expiration without updating data HOT 1
- i have been hack HOT 5
- Upgrade @fastify/cookie to 9.1.0 HOT 1
- Considering adding proprietary cookies good practices as Chrome make big changes on cookies in 2024 HOT 2
- typescript types don't work properly HOT 3
- changed value should be set to true when modifying objects within session HOT 1
- "reply.signCookie is not a function" when setting option signed: true HOT 2
- New "expiry" is not included in TypeScript definition HOT 2
- No way to update session expiration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-secure-session.