Преглед на файлове

Verify `share_token` when launched

Nariman Jelveh преди 11 месеца
родител
ревизия
5cb5a75455
променени са 1 файла, в които са добавени 34 реда и са изтрити 0 реда
  1. 34 0
      src/initgui.js

+ 34 - 0
src/initgui.js

@@ -210,6 +210,40 @@ window.initgui = async function(options){
         }
     }
 
+    //--------------------------------------------------------------------------------------
+    // `share_token` provided
+    // i.e. https://puter.com/?share_token=<share_token>
+    //--------------------------------------------------------------------------------------
+    if(window.url_query_params.has('share_token')){
+        let share_token = window.url_query_params.get('share_token');
+
+        fetch(`${config.api_origin}/sharelink/check`, {
+            "headers": {
+              "Content-Type": "application/json",
+              "Authorization": `Bearer ${puter.authToken}`,
+            },
+            "body": JSON.stringify({
+                token: share_token,
+            }),
+            "method": "POST",
+        }).then(response => response.json())
+        .then(async data => {
+            if(data.success){
+                if(data.email && data.email !== window.user.email){
+                    UIAlert({
+                        message: 'You are not authorized to view this link.'
+                    });
+                }else{
+                    UIAlert({
+                        type: 'success',
+                        message: 'You are authorized to view this link.'
+                    });
+                }
+            }
+        }).catch(error => {
+            console.error('Error:', error);
+        })
+    }
     //--------------------------------------------------------------------------------------
     // Determine if an app was launched from URL
     // i.e. https://puter.com/app/<app_name>