How to fix MemberStack connection issues with valid API keys in Next.js Stripe integration?

Post author
Abdulrahman Laoye

Hello team, please I am a developer working on a Nextjs project where I want to use MemberStack to automate my stripe payment package but having issues with Memberstack connection. The users are accepted by db but memberstack is not accepting the connection. It is saying, submit a valid key and I have used the correct keys. I don't know who can help you solve this issue. Thanks

Comments

4 comments

  • Comment author
    Raquel Lopez

    What method of which package (admin or Dom) are you trying to use?

    I created an unofficial Nextjs starter template, that you can use as an example on how to connect with Memberstack https://github.com/raqlo/template-nextjs-memberstack

    0
  • Comment author
    Abdulrahman Laoye

    Thanks, I am using the admin SDK because I just want the client to replace my .env values with his own .env without changing any of the codes

    Thanks for helping me out but the issue I am getting is the key is an invalid API key

    0
  • Comment author
    Raquel Lopez

    The admin package can be used using via the Node package or the REST package. You must pass a secret key to be able to connect via the admin, it can be found in the dev tools. If you're using test mode your secret key will start as sk_sb_... and if you're building for production the prefix will change to only sk_...

    If you're using the REST package you need to send the api key via headers

     const response = await axios.get(
          `https://admin.memberstack.com/members/${memberId}`,
          { headers: { 'X-API-KEY': process.env.MEMBERSTACK_SECRET_KEY } }
        );
    

    If you're using the NodeJS package you have to first initialize the singleton and pass the secret key before using it in any of your services

    import memberstackAdmin from "@memberstack/admin";
    
    // Initialize with your secret key
    const memberstack = memberstackAdmin.init(process.env.MEMBERSTACK_SECRET_KEY);
    

    Without more context or code preview I am unable to provide a more accurate solution to your problem. Hopefully this helps.

    key is an invalid API key

    Make sure to use the keys first as plain text to initially test the connection and if all works, then test your dotenv configuration to make sure the environments variable are setup correctly

    0
  • Comment author
    Abdulrahman Laoye

    Yeah, I will try it but you have done a great job in putting me through. Thanks for the assistance.

    0

Please sign in to leave a comment.