MomenSherif / react-oauth

Google OAuth2 using the new Google Identity Services SDK for React 🚀
https://www.npmjs.com/package/@react-oauth/google
MIT License
1.1k stars 139 forks source link

Production build error "Failed to set the 'src' property on HTMLScriptElement #18

Closed oliverilm closed 2 years ago

oliverilm commented 2 years ago

Working in development env, everything works great, but as soon as i make a release and the code gets hosted, the application crashes on initial load (only white screen is displayed)

Error displayed: react-dom.production.min.js:216 TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.

image

if i open the traceback, the issue is highlighted image

MomenSherif commented 2 years ago

@oliverilm I'm sorry for that but the issue is related to CSP is blocking any external scripts (for example here google)

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src

https://www.loginradius.com/blog/engineering/content-security-policy/

try to update CSP header on your server to allow for your scripts & google.

you can also try to load google's script alone https://developers.google.com/identity/gsi/web/guides/client-library, It should be blocked also

MomenSherif commented 2 years ago

Here's an example of production demo http://test-oauth-rust.vercel.app/

and I looked for other user's websites that using the package and it was wroking