Cookies do not get set

Viewed 40

I am trying to set a cookie with the npm cookies-package, but somehow the cookie does not get set properly.

The resolver has a login method:

login: async (parent: any, args: any, context: any) => {
    const { req, res } = context

    const { loginInput } = args
    const { email, password } = loginInput

    const user = await prisma.user.findUnique({
        where: { email }
    })

    if (user && (await compare(password, user.password))) {
        const secret = process.env.SECRET
        const token = secret ? sign({ id: user.id }, secret) : null
        if (token) {
            const cookies = new Cookies(req, res)
            cookies.set('token', token)
            return true
        }
    }

    return false
}
0 Answers
Related