Skip to content

Redis v4 config problem & solution (so you don't have to sweat) #53

@Chriskuiper1

Description

@Chriskuiper1

When installing Redis @ 1:41h and testing the auth cookie, graphql will crash. This is because the new version of Redis (v4) doesn't support the code from the tuturial. The codeblock below will fix this. You can find the full documentation here: https://www.npmjs.com/package/connect-redis

const session = require("express-session");
let RedisStore = require("connect-redis")(session);

const main = async () => {
	const orm = await MikroORM.init(microConfig);
	await orm.getMigrator().up();

	const { createClient } = require("redis");
	let redisClient = createClient({ legacyMode: true });

	redisClient.on("connect", () => console.log("Connected to Redis!"));
	redisClient.on("error", (err: Error) =>
		console.log("Redis Client Error", err)
	);
	redisClient.connect();

	const app = express();

	app.use(
		session({
			name: "qid",
			store: new RedisStore({
				client: redisClient,
				disableTouch: true,
			}),
			cookie: {
				maxAge: 1000 * 60 * 60 * 24 * 365 * 1, // 1 year
				httpOnly: true,
				sameSite: "lax",
				secure: __prod__, // cookie only works in https
			},
			saveUninitialized: false,
			secret: "bruhhhh",
			resave: false,
		})
	);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions