Code Monkey home page Code Monkey logo

Comments (6)

FC5570 avatar FC5570 commented on August 23, 2024

Ended up writing a small store of my own, simply just set/get/delete the values in the set, get and destroy method of the store options.

from connect-redis.

mrbrianevans avatar mrbrianevans commented on August 23, 2024

I built an application that used connect-redis with @fastify/session in 2022 and it all worked perfectly. Now I tried updating the connect-redis package to v7 and breaks irrepairably.
Seems unfortunate to have broken the usage of the package with fastify all together as I suppose now I'll have to do a custom implementation like @FC5570 and uninstall the connect-redis package.
Was this intentional when publishing v7? @wavded
Would it be possible to publish a different import that allows setting the session object to something other than express-session?

from connect-redis.

wavded avatar wavded commented on August 23, 2024

Seems like this should be doable, was unaware that this was being used for other session managers so my apologies there. Looks like @fastify must have mimicked the connect-session API for this to have worked prior.

from connect-redis.

wavded avatar wavded commented on August 23, 2024

@mrbrianevans I am able to run connect-redis and fastify in my testing. However the connect-session may still need to be installed (only used for typing information). This program tested fine for me:

import {fastifyCookie} from "@fastify/cookie"
import {fastifySession} from "@fastify/session"
import fastify from "fastify"
import {createClient} from "redis"
import RedisStore from "connect-redis"

declare module "fastify" {
  interface Session {
    foo: string
  }
}

let redisClient = createClient()
redisClient.connect().catch(console.error)

let redisStore = new RedisStore({
  client: redisClient,
  prefix: "myapp:",
})

const app = fastify()

app.register(fastifyCookie)
app.register(fastifySession, {
  store: redisStore,
  secret: "a secret with minimum length of 32 characters",
  cookie: {secure: false},
})

app.get("/", (req, res) => {
  res.send("data: " + req.session.foo)
})

app.get("/set", (req, res) => {
  req.session.foo = (req.query as any).data
  res.send("set data")
})

app.listen({port: 3000})

We probably could make the types generic so you wouldn't need to install connect-session.

from connect-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.