ctrlaltdylan / shopify-nextjs-toolbox

A set of tools to authenticate NextJs apps with Shopify's OAuth handshake and AppBridge Session Tokens
161 stars 21 forks source link

handleAuthStart produces error when trying to pass 'nonce' #11

Closed DaveMitten closed 2 years ago

DaveMitten commented 2 years ago

Hey all!

Wanted to say thank you for this project. I have an issue that may be my misuse but I am unsure (even with reading the package files)

error - TypeError: Cannot read property 'query' of undefined

auth.ts:

import { handleAuthStart } from "shopify-nextjs-toolbox";
import { app, apps, initializeApp, firestore } from "firebase";

const generateNonce = async (req) => {
  const config = {
    apiKey: "<nope>",
    authDomain:"<nope>"
    // databaseURL: "<nope>"
    databaseURL: "<nope>"
    projectId: "<nope>"
    storageBucket: "<nope>"
    messagingSenderId: "<nope>"
    appId:"<nope>"
    measurementId:"<nope>"
  };

  if (!apps.length) {
    await initializeApp(config);
  } else {
    await app();
  }

  function createRandomNumber(min: number, max: number) {
    return Math.floor(Math.random() * (max - min + 1) + min);
  }

  const random = createRandomNumber(1000, 999999).toString();
  return await firestore()
    .collection("")
    .doc("")
    .collection("")
    .doc("nonce")
    .set({ nonceValue: random });
};

export default handleAuthStart({ generateNonce });

Without the generateNonce being passed to handleAuthStart, it clears this section.

Currently, when calling req.body.query it returns undefined

Any idea why I am getting this error?

ctrlaltdylan commented 2 years ago

@DaveMitten can you provide the version of the package you're using in the implementation?

ctrlaltdylan commented 2 years ago

Please update to v2 of the package, which includes an optional saveNonce during handleAuthStart. The package handles generating a one time nonce and you can just pass a function to store it.