Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the edge function crash on Vercel #84

Merged
merged 6 commits into from
Jul 15, 2024
Merged

Conversation

marcomontalbano
Copy link
Member

@marcomontalbano marcomontalbano commented Jul 12, 2024

What I did

Use btoa and atob directly without checking globalThis nor window.

Before this fix the edge function was crashing on Vercel:

TypeError: Illegal invocation
    at (../src/utils/base64.ts:41:22)
    at (../src/jwtDecode.ts:18:23)
    at (../src/jwtVerify.ts:14:31)
    at (src/middlewares/withCommerceLayer.ts:15:31)
    at (node_modules/.pnpm/next@14.2.5_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/next/dist/esm/server/web/adapter.js:158:0)

I also added a Next.js example deployed on Vercel and Netlify.

How to test

This example is now working as expected: https://commercelayer-js-auth-nextjs.vercel.app/middleware

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests).
  • Make sure to add/update documentation regarding your changes.
  • You are NOT deprecating/removing a feature.

Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
commercelayer-js-auth-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 2:25pm

Copy link

netlify bot commented Jul 12, 2024

Deploy Preview for commercelayer-js-auth-nextjs ready!

Name Link
🔨 Latest commit 6c1976a
🔍 Latest deploy log https://app.netlify.com/sites/commercelayer-js-auth-nextjs/deploys/66913cc2f43b6d00087f9e10
😎 Deploy Preview https://deploy-preview-84--commercelayer-js-auth-nextjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@marcomontalbano marcomontalbano added the bug Something isn't working label Jul 12, 2024
@marcomontalbano marcomontalbano self-assigned this Jul 12, 2024
@marcomontalbano marcomontalbano changed the title Fix vercel edge Fix the edge function crash on Vercel Jul 12, 2024
Copy link
Member

@acasazza acasazza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants