vesper icon indicating copy to clipboard operation
vesper copied to clipboard

Apollo context

Open AaronNGray opened this issue 4 years ago • 0 comments

Is it still possible to use Apollo context option for authentication like DataLoader is still avalable through context IIRC seeing the code.

If so how do I do it as the following does not seem to be being called at all.

    app.use("/graphql", bodyParser.json(), vesper(schema, {
        setupContainer: async (container, action) => {
            console.log("setupContainer()");
            const request = action.request;
            const token:string = request.headers["token"] as string || "";

            if (token !== "") {
                const entityManager = getManager();
                const payload = jwt.verify(token, "secret");
                const currentUser = await entityManager.findOneOrFail(User, { id: payload["id"] });

                container.set(User, currentUser);
                console.log("this.currentUser = ", currentUser);
            }
        }
    }));

as the above does not seem to be doing anything a

AaronNGray avatar Jul 30 '21 00:07 AaronNGray