File size: 13,539 Bytes
77f6e8e
 
 
 
 
e929229
e95f316
a2a096a
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e929229
77f6e8e
 
 
 
 
 
 
 
323c8be
77f6e8e
e95f316
77f6e8e
e95f316
77f6e8e
309a270
 
323c8be
 
309a270
 
 
 
 
 
 
323c8be
 
 
309a270
323c8be
 
309a270
 
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e95f316
 
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
dedd362
77f6e8e
 
 
 
323c8be
309a270
 
 
 
323c8be
 
77f6e8e
 
e95f316
77f6e8e
 
 
e95f316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77f6e8e
 
 
 
 
 
 
 
 
 
 
 
 
323c8be
77f6e8e
309a270
77f6e8e
 
e929229
 
 
 
 
77f6e8e
e95f316
 
e929229
309a270
323c8be
 
309a270
323c8be
e929229
77f6e8e
 
e929229
 
 
 
 
 
 
 
e95f316
 
 
e929229
 
 
 
77f6e8e
 
 
 
 
309a270
 
 
 
 
 
 
 
323c8be
309a270
323c8be
309a270
 
 
 
 
 
77f6e8e
 
 
 
 
 
 
e95f316
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi Agent Research</title>
    <script src="https://unpkg.com/@supabase/supabase-js@2"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            font-family: 'Roboto', sans-serif;
        }
        #app {
            height: 100%;
            display: flex;
            flex-direction: column;
        }
        .content-wrapper {
            flex-grow: 1;
            position: relative;
            overflow: hidden;
        }
        iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border: none;
        }
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            bottom: 0;
            width: 250px;
            background-color: #2c3e50;
            color: white;
            display: flex;
            flex-direction: column;
            transition: transform 0.3s ease-in-out;
            transform: translateX(-100%);
            overflow-y: auto;
            padding-top: 60px;
            z-index: 1000;
        }
        .sidebar.open {
            transform: translateX(0);
        }
        .sidebar button {
            width: 80%;
            margin: 10px auto;
            padding: 15px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            cursor: pointer;
            text-align: center;
            transition: all 0.3s ease;
            display: block;
        }
        .sidebar button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        .toggle-btn {
            position: fixed;
            left: 10px;
            top: 10px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            cursor: pointer;
            padding: 7px 15px;
            z-index: 1001;
            transition: background-color 0.3s ease;
        }
        .toggle-btn:hover {
            background-color: #2980b9;
        }
        .category {
            width: 100%;
            margin-bottom: 20px;
        }
        .category-title {
            width: 80%;
            margin: 10px auto;
            padding: 10px;
            background-color: #34495e;
            color: white;
            border-radius: 10px;
            font-size: 16px;
            text-align: center;
            cursor: pointer;
        }
        .category-content {
            display: none;
            width: 100%;
        }
        .category-content.show {
            display: block;
        }
        .user-info {
            width: 80%;
            margin: 20px auto;
            text-align: center;
        }
        .user-name {
            margin-bottom: 10px;
            font-weight: bold;
        }
        .logout-btn {
            background-color: #e74c3c;
        }
        .logout-btn:hover {
            background-color: #c0392b;
        }

        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
            }
            .sidebar button, .category-title, .user-info {
                width: 90%;
            }
        }

        @media (max-width: 480px) {
            .sidebar button, .category-title, .user-info {
                width: 95%;
            }
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-if="loading">Loading...</div>
        <div v-else-if="error">{{ error }}</div>
        <div v-else class="content-wrapper">
            <div class="sidebar" :class="{ 'open': sidebarOpen }" id="sidebar">
                <div v-for="(apps, category) in appData" :key="category" class="category">
                    <div class="category-title" @click="toggleCategory">{{ category }}</div>
                    <div class="category-content">
                        <button v-for="app in apps" :key="app.name" @click="switchToApp(app.url)">{{ app.name }}</button>
                    </div>
                </div>
                <div class="user-info">
                    <div class="user-name">{{ userName }}</div>
                    <button class="logout-btn" @click="handleLogout">Logout</button>
                </div>
            </div>

            <button class="toggle-btn" @click="toggleSidebar"></button>
            <iframe :src="currentPage" id="iframe" allowfullscreen allow="clipboard-read; clipboard-write" sandbox="allow-scripts allow-same-origin allow-popups allow-forms allow-downloads"></iframe>
        </div>
    </div>

        <script>
        const { createApp } = Vue;
        const { createClient } = supabase;

        const supabaseClient = createClient('https://ftqmmutydpjseodidugl.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ0cW1tdXR5ZHBqc2VvZGlkdWdsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTQzMTE2MzQsImV4cCI6MjAyOTg4NzYzNH0.2h1uLIPCKrwF8f9enRChU_Q2qkhoQlR4gwlehL-h0a4');

        function setCookie(name, value, days) {
            const expires = new Date(Date.now() + days * 864e5).toUTCString();
            document.cookie = name + '=' + encodeURIComponent(JSON.stringify(value)) + '; expires=' + expires + '; path=/; SameSite=Strict';
            console.log(`Cookie set: ${name}`, value);
        }

        function getCookie(name) {
            const value = `; ${document.cookie}`;
            const parts = value.split(`; ${name}=`);
            if (parts.length === 2) {
                const cookieValue = parts.pop().split(';').shift();
                const decodedValue = JSON.parse(decodeURIComponent(cookieValue));
                console.log(`Cookie retrieved: ${name}`, decodedValue);
                return decodedValue;
            }
            console.log(`Cookie not found: ${name}`);
            return null;
        }

        const app = createApp({
            data() {
                return {
                    appData: {},
                    currentPage: '',
                    loading: true,
                    error: null,
                    sidebarOpen: false,
                    userName: ''
                }
            },
            methods: {
                async checkAuth() {
                    try {
                        console.log("Checking authentication");
                        const { data: { session }, error } = await supabaseClient.auth.getSession();
                        if (error) throw error;
                        console.log("Session:", session);
                        return session;
                    } catch (error) {
                        console.error("Not authenticated", error);
                        return null;
                    }
                },
                redirectToLogin() {
                    console.log("Redirecting to login");
                    window.location.href = '/';
                },
                async checkAllowlist(email) {
                    try {
                        console.log("Checking allowlist for email:", email);
                        const response = await axios.post('/check-allowlist', { email });
                        console.log("Received response:", response.data);
                        if (response.data.allowed) {
                            console.log("Access allowed, setting app data");
                            this.appData = response.data.app_data;
                            this.currentPage = this.currentPage || this.appData["Updated Tools"][0].url;
                            
                            // Store app_data and current page URL in cookies
                            setCookie('app_data', this.appData, 7); // Store for 7 days
                            setCookie('current_page', this.currentPage, 7);
                            
                            console.log("Stored app_data and current_page in cookies", this.appData, this.currentPage);
                        } else {
                            console.log("Access denied");
                            this.error = `Access Denied: Your email (${email}) is not on the allowlist. Server message: ${response.data.message || 'No additional information provided.'}`;
                        }
                    } catch (error) {
                        console.error("Error checking allowlist:", error);
                        let errorMessage = 'An error occurred while checking access.';
                        if (error.response) {
                            // The request was made and the server responded with a status code
                            // that falls out of the range of 2xx
                            errorMessage += ` Server responded with status ${error.response.status}.`;
                            if (error.response.data && error.response.data.message) {
                                errorMessage += ` Message: ${error.response.data.message}`;
                            }
                        } else if (error.request) {
                            // The request was made but no response was received
                            errorMessage += ' No response received from server.';
                        } else {
                            // Something happened in setting up the request that triggered an Error
                            errorMessage += ` Error message: ${error.message}`;
                        }
                        this.error = `Error for email (${email}): ${errorMessage}`;
                    } finally {
                        console.log("Setting loading to false");
                        this.loading = false;
                    }
                },
                toggleSidebar() {
                    this.sidebarOpen = !this.sidebarOpen;
                },
                toggleCategory(event) {
                    const content = event.target.nextElementSibling;
                    content.classList.toggle('show');
                },
                switchToApp(url) {
                    console.log("Switching to app:", url);
                    this.currentPage = url;
                    setCookie('current_page', url, 7);
                    this.toggleSidebar();
                },
                async handleLogout() {
                    const loadingElement = document.createElement('div');
                    loadingElement.textContent = 'Logging out...';
                    document.body.appendChild(loadingElement);

                    try {
                        const { error } = await supabaseClient.auth.signOut();
                        if (error) throw error;

                        // Clear cookies
                        document.cookie = 'app_data=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Strict';
                        document.cookie = 'current_page=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Strict';

                        console.log("Cookies cleared");
                        localStorage.clear();
                        this.redirectToLogin();
                    } catch (error) {
                        console.error("Logout failed:", error);
                        alert("Logout failed. Please try again.");
                    } finally {
                        document.body.removeChild(loadingElement);
                    }
                },
                async fetchProfileInfo() {
                    try {
                        const { data: { user }, error } = await supabaseClient.auth.getUser();
                        if (error) throw error;
                        this.userName = user.user_metadata.full_name || user.email || 'User';
                        await this.checkAllowlist(user.email);
                    } catch (error) {
                        console.error("Error fetching profile info:", error);
                        this.error = 'Error loading profile information.';
                    }
                }
            },
            async mounted() {
                console.log("Component mounted");
                const storedAppData = getCookie('app_data');
                const storedCurrentPage = getCookie('current_page');

                if (storedAppData && storedCurrentPage) {
                    console.log("Found stored data in cookies");
                    this.appData = storedAppData;
                    this.currentPage = storedCurrentPage;
                    this.loading = false;
                    console.log("Set app data and current page from cookies:", this.appData, this.currentPage);
                } else {
                    console.log("No stored data found in cookies");
                    const session = await this.checkAuth();
                    if (!session) {
                        this.redirectToLogin();
                    } else {
                        await this.fetchProfileInfo();
                    }
                }
            }
        });

        app.mount('#app');
    </script>
</body>
</html>