seratch / slack-edge

Slack app development framework for edge functions with streamlined TypeScript support
https://github.com/seratch/slack-edge-app-template
MIT License
91 stars 5 forks source link

TypeError in request-verification.js after upgrading from Next.js v13 to v14 with Edge Functions #24

Closed abc123931 closed 6 months ago

abc123931 commented 6 months ago

We recently upgraded our project from Next.js v13.3.1 to v14.2.1 and are using slack-edge v0.10.9.

After upgrading our project from Next.js v13 to v14 and utilizing Edge Functions, we started encountering a TypeError when attempting to verify a request using the SubtleCrypto.verify method in the request-verification.js module.

The error message indicates that the third argument passed to SubtleCrypto.verify is not an instance of ArrayBuffer, Buffer, TypedArray, or DataView. This issue only arose after the upgrade, suggesting a potential compatibility problem with the new version of Next.js or its implementation of Edge Functions. Here is the complete error message for reference:

⨯ Error [TypeError]: Failed to execute 'verify' on 'SubtleCrypto': 3rd argument is not instance of ArrayBuffer, Buffer, TypedArray, or DataView.
     at codedTypeError (node:internal/crypto/webidl:45:15)
     at makeException (node:internal/crypto/webidl:54:10)
     at converters.BufferSource (node:internal/crypto/webidl:218:11)
     at SubtleCrypto.verify (node:internal/crypto/webcrypto:870:33)
     at verifySlackRequest (webpack-internal:///(middleware)/../../node_modules/slack-edge/dist/request/request-verification.js:20:32)
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I would appreciate any guidance on how to address this issue or any updates if this is a known bug, especially in relation to changes between Next.js v13 and v14. Thank you for your assistance.

seratch commented 6 months ago

Hi @abc123931, thanks for sharing this. It seems that the behavior of this method might differ slightly in your context: https://github.com/seratch/slack-edge/blob/0.10.9/src/request/request-verification.ts#L32

Personally, I don't use Next.js and Vercel's platform, so I haven't encountered this issue. Nevertheless, I am open towards modifying the code to support your specific requirement.

abc123931 commented 6 months ago

Thank you very much for your prompt response and willingness to adapt the code. I appreciate your support!

I would like to assist in resolving this issue. Could you please inform me about any specific requirements or details you need to be included in the fix? Additionally, I am considering making the necessary adjustments on my end and submitting a pull request. Would that be a helpful approach for you?

seratch commented 6 months ago

Would it be possible to reproduce the issue without Vercel runtime? If yes, reproducing the error would be much easier and I may be able to take time to work on the fix.

If this is an urgent need for you, sending a pull request to resolve it would be appreciated.

abc123931 commented 6 months ago

@seratch I have submitted a pull request; please review it when you have a chance. Thank you!

seratch commented 6 months ago

Fixed by #25