saasufy-components 10.5.2 → 10.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +18 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -232,7 +232,24 @@ Saasufy enforces access controls for HTTP in the same way as it does for its Web
232
232
  It's possible to block or restrict access to specific files stored on specific fields via the `Access` page under the relevant model.
233
233
 
234
234
  If your model field's access is set to `restrict`, only authenticated users with matching permissions will be able to view/download the image/file.
235
- In this case, you will need to add your user's JWT token to a cookie with the name `socketcluster.saasufyService.authToken` and it will be passed along with the request.
235
+ In this case the request has to carry the user's signed JWT in an `Authorization: Bearer <signedAuthToken>` header; the token is the `signedAuthToken` of your `socket-provider`'s socket.
236
+
237
+ Headers cannot be attached to an `<img src="...">`, so fetch the file yourself and hand the element an object URL:
238
+
239
+ ```js
240
+ let socket = document.querySelector('socket-provider').saasufySocket;
241
+
242
+ let response = await fetch('https://sid7999.saasufy.com/files/Image/58f2051c-14bc-4518-8816-ff387cfdd57e/data', {
243
+ headers: { Authorization: `Bearer ${socket.signedAuthToken}` }
244
+ });
245
+
246
+ let img = document.querySelector('img');
247
+ img.src = URL.createObjectURL(await response.blob());
248
+ ```
249
+
250
+ Remember to `URL.revokeObjectURL(img.src)` once you are done with it.
251
+
252
+ Because files are served on a subdomain of their own, that fetch is a cross-origin request and the browser preflights it. Your app's origin therefore has to appear in the **Files allow origin** setting on the Saasufy settings page, which defaults to `*`. Files which are not restricted need none of this - an `<img>` tag is not subject to CORS.
236
253
 
237
254
  ## Components
238
255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "10.5.2",
3
+ "version": "10.5.3",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {