cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch from neo4j database inside custom resolver

julian_deflandr
Node Link

Could someone help me understand how to reach out to my neo4j database to check if a user exists inside my custom resolver for login?

 Mutation: {
    register: async (_, { id, email, password }, context, info) => {
      const hashedPassword = await bcrypt.hash(password, 10);
      return neo4jgraphql(_, { id, email, password }, context, info);
    },
    login: async (_, { email, password }, context, info) => {

      const user  =  //check neo4j database for existing user to log in
      if (!user) {
        return "user not found";
      }

      const valid = await bcrypt.compare(password, user.password);
      if (!valid) {
        return null;
      }

      const refreshToken = sign(
        { userId: user.id, count: user.count },
        REFRESH_TOKEN_SECRET,
        {
          expiresIn: "30d"
        }
      );
      const accessToken = sign({ userId: user.id }, ACCESS_TOKEN_SECRET, {
        expiresIn: "1day"
      });

      context.res.cookie("refresh-token", refreshToken);
      context.res.cookie("access-token", accessToken);

      return user;
    }
  }

I'm not sure how to reach the database when you need more than simply calling neo4jgraphql() in the return of the resolver.

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.