![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@ethicdevs/fastify-custom-session
Advanced tools
A Fastify (v3.x+) plugin that let you use session and decide only where to load/save from/to
fastify-custom-session
A Fastify (v3.x+) plugin that let you use session and decide only where to load/save from/to through the adapter pattern.
$ yarn add @ethicdevs/fastify-custom-session
# or
$ npm i @ethicdevs/fastify-custom-session
import fastifyCookies from "@fastify/cookie";
import fastifyCustomSession, {
FirebaseSessionAdapter, // Firebase Firestore adapter
MockSessionAdapter, // In Memory adapter (for testing)
PostgresSessionAdapter, // PostgreSQL adapter (pg/pg-pool)
PrismaSessionAdapter, // Prisma Client adapter
} from "@ethicdevs/fastify-custom-session";
let server = null;
function main() {
server = fastify(); // provide your own
// some cookies options
const cookieSecret = "super-secret-session-secret"; // or better: Env.SESSION_SECRET
const cookiesOptions = {
domain: `.my-app.com`, // or better: `.${Env.DEPLOYMENT_DOMAIN}`,
httpOnly: true,
expires: new Date(Date.now() + 10 * (8 * 3600) * 1000), // 10 days in secs
path: "/",
secure: false,
sameSite: "lax",
signed: true,
};
// register the cookies plugin FIRST.
server.register(fastifyCookies, {
parseOptions: cookiesOptions,
secret: cookieSecret,
});
// then register the customSession plugin.
server.register(fastifyCustomSession, {
password: cookieSecret,
cookieName: "my_app_session_id", // or better: Env.COOKIE_NAME,
cookieOptions,
storeAdapter: new MockSessionAdapter({
/* ... AdapterOptions ... */
}) as any,
ttl: 30 * 60, // expire session after 30 minutes (in seconds)
initialSession: { // initial data in session (so you can avoid null's)
whateverYouWant: '<unset>',
aNullableProp: null,
mySuperObject: {
foo: '<unset>',
bar: 0,
baz: '<unset>',
};
},
});
}
main();
then if you are a TypeScript user you will need to define the shape of the
session.data
object, you can do so easily by adding the following lines to your
types/global/index.d.ts
file:
// use declaration merging to provide custom session interface
declare module "@ethicdevs/fastify-custom-session" {
declare interface CustomSession {
// request.session.data shape
whateverYouWant: string;
aNullableProp: null | string;
mySuperObject: {
foo: string;
bar: number;
baz: string;
};
}
}
later on during request before you send the headers/response, typically in your controller/handler:
const myRequestHandler = async (request, reply) => {
request.session.data.whateverYouWant = "foo";
request.session.data.aNullableProp = "not null anymore";
request.session.data.mySuperObject = {
foo: "bar",
bar: 42,
baz: "quxx",
};
return reply.send("Hello with session!");
};
const mySecondRequestHandler = async (request, reply) => {
// if you're a typescript user, enjoy ;)
/* request.session.data.
| [p] whateverYouWant
| [p] mySuperObject */
request.session.data.whateverYouWant; // "foo"
request.session.data.aNullableProp; // "not null anymore"
request.session.data.object.foo; // "bar"
request.session.data.object.bar; // 42
return reply.send(
"Cool value from session:" + request.session.data.object.baz,
);
// "Cool value from session: quxx"
};
then enjoy the session being available both in your controllers/handlers and in your data store table/collection (linked to the Adapter you chosen in first step).
This library make use of the debug
package,
thus it's possible to make the output of the program more verbose.
The plugin itself, and the adapters have their own "scopes" of logs so its possible to troubleshoot only with logs from the plugin, or with logs from the adapter(s) or both.
# Syntax and examples:
# DEBUG=$scope:$subscope $(...command)
# Show all logs kinds from the customSession plugin
$ DEBUG=customSession:* yarn dev
# Show only trace logs from the customSession plugin
$ DEBUG=customSession:trace yarn dev
# Show only error logs from the customSession plugin
$ DEBUG=customSession:error yarn dev
Note: in this example, $scope
could be:
customSession
;firebaseSessionAdapter
;mockSessionAdapter
;prismaSessionAdapter
;postgresSessionAdapter
;yourOwnSessionAdapter
.The MIT license.
FAQs
A Fastify (v3.x+) plugin that let you use session and decide only where to load/save from/to
We found that @ethicdevs/fastify-custom-session demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.