nextjs-shopify-app icon indicating copy to clipboard operation
nextjs-shopify-app copied to clipboard

Question about the `afterAuth` signature

Open arsnl opened this issue 2 years ago • 1 comments

Hi @t-kelly !

First of all, great work! I really enjoy looking at that serverless Shopify App example and learned a lot from it. :)

I have a question about the code below.

https://github.com/t-kelly/nextjs-shopify-app/blob/1e61d7acc7ced6545484b35c4f59c4bd9fee8801/lib/shopify.js#L76-L78

To my understanding, the goal here is to retrieve a new redirectUrl value returned from the afterAuth promise. If this value is a truthy (a non-empty string, in that case), we assign it to redirectUrl. Else we simply use the original redirectUrl value.

However, after reading the afterAuth promise, I see that it doesn't return anything (Promise<void>) and only do side effects. Because of that, the condition will simply always keep the same value for redirectUrl.

https://github.com/t-kelly/nextjs-shopify-app/blob/1e61d7acc7ced6545484b35c4f59c4bd9fee8801/pages/api/auth/%5B...shopify%5D.js#L4-L27

So, I'm not sure. Did I misunderstood something or it is not the researched effect?

arsnl avatar Jul 22 '21 22:07 arsnl

Hey @arsnl - since the return value is optional i assume the afterAuth method has multiple purposes.

  1. overwrite the default redirectUrl
  2. be a hook for you to store the session, update context, register a webhook etc. etc.

It's ages since you asked and might not be that useful now - i just stumbled upon you're question :)

schonert avatar Nov 24 '21 11:11 schonert