Please help me make my session initialize.
I'm using express-session connect-redis and ioredis to store my sessions and typegraphql as my graphql API framework.
MyContext.ts
interface MyContext {
req: Request & {
session: {
userId: number;
};
};
LoginResolver.ts
import {User} from "../entities/User";
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
import MyContext from "../MyContext";
@Resolver()
class LoginResolver {
@Mutation(() => Boolean)
async login(
@Arg("username") username: string,
@Arg("password") password: string,
@Ctx() ctx: MyContext
) {
const user = await User.findOne({ username: username});
if(!user)
return false;
const vaild = user.password == password;
if(!vaild)
return false;
ctx.req.session.userId = user.id;
return true;
}
}
When I use saveUninitialized: true the session is stored but when I modify it in LoginResolver it doesn't work thus if saveUninitialized: false the session is not initializing.
question from:
https://stackoverflow.com/questions/65645422/my-session-is-not-initializing-using-express-session-and-redis 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…