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: Fetch manifest with credentials over CORS #5156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samvrlewis
Copy link

@samvrlewis samvrlewis commented Jan 1, 2025

Summary

When behind authentication (for eg: Cloudflare Access), browsers
won't send credentials when fetching the manifest file by default.

To fix, this change adds crossorigin="use-credentials" to the
manifest link tag which allows the browser to attach credentials.
Because of limitations with Vite, for now this needs to happen as
a manual post build step.

Change Type

Please delete any irrelevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Translation update

Testing

Ran npm run frontend and ensured the manifest link in client/dist/index.html had the expected crossorigin attribute.

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code

client/vite.config.ts Outdated Show resolved Hide resolved
@danny-avila
Copy link
Owner

@samvrlewis Since the manifest file is generated by vite-plugin-pwa, can you double check there is no option to do this through that library before trying it this way?

I only just thought of this, and looking at it, it may as simple as this:
https://vite-pwa-org.netlify.app/guide/faq.html#web-app-manifest-and-401-status-code-unauthorized

Copy link
Owner

@danny-avila danny-avila left a comment

Choose a reason for hiding this comment

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

Please see: #5156 (comment)

@samvrlewis
Copy link
Author

@samvrlewis Since the manifest file is generated by vite-plugin-pwa, can you double check there is no option to do this through that library before trying it this way?

I only just thought of this, and looking at it, it may as simple as this: https://vite-pwa-org.netlify.app/guide/faq.html#web-app-manifest-and-401-status-code-unauthorized

Great spot, I can't believe I missed this. Tested and it seems to work perfectly! Have updated this PR to do it that way.

When behind authentication (for eg: Cloudflare Access), browsers
won't send credentials when fetching the manifest file by default.

To fix, this change adds `crossorigin="use-credentials"` to the
manifest link tag by enabling the `useCredentials` option in
VitePWA.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants