cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to fetch from neo4j database inside custom resolver

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