Spaces:
Sleeping
Sleeping
Update static/mult-agent-auth.html
Browse files- static/mult-agent-auth.html +28 -18
static/mult-agent-auth.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Multi Agent Research</title>
|
| 7 |
-
<script src="https://
|
| 8 |
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
| 10 |
<style>
|
|
@@ -167,12 +167,9 @@
|
|
| 167 |
|
| 168 |
<script>
|
| 169 |
const { createApp } = Vue;
|
|
|
|
| 170 |
|
| 171 |
-
const
|
| 172 |
-
client.setEndpoint('https://cloud.appwrite.io/v1')
|
| 173 |
-
.setProject('66c2f6c7000abed7f1f9');
|
| 174 |
-
|
| 175 |
-
const account = new Appwrite.Account(client);
|
| 176 |
|
| 177 |
function setCookie(name, value, days) {
|
| 178 |
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
@@ -208,7 +205,8 @@
|
|
| 208 |
async checkAuth() {
|
| 209 |
try {
|
| 210 |
console.log("Checking authentication");
|
| 211 |
-
const session = await
|
|
|
|
| 212 |
console.log("Session:", session);
|
| 213 |
return session;
|
| 214 |
} catch (error) {
|
|
@@ -237,11 +235,26 @@
|
|
| 237 |
console.log("Stored app_data and current_page in cookies", this.appData, this.currentPage);
|
| 238 |
} else {
|
| 239 |
console.log("Access denied");
|
| 240 |
-
this.error =
|
| 241 |
}
|
| 242 |
} catch (error) {
|
| 243 |
console.error("Error checking allowlist:", error);
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
} finally {
|
| 246 |
console.log("Setting loading to false");
|
| 247 |
this.loading = false;
|
|
@@ -266,12 +279,8 @@
|
|
| 266 |
document.body.appendChild(loadingElement);
|
| 267 |
|
| 268 |
try {
|
| 269 |
-
const
|
| 270 |
-
|
| 271 |
-
setTimeout(() => reject(new Error('Logout timed out')), 5000)
|
| 272 |
-
);
|
| 273 |
-
|
| 274 |
-
await Promise.race([logoutPromise, timeoutPromise]);
|
| 275 |
|
| 276 |
// Clear cookies
|
| 277 |
document.cookie = 'app_data=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Strict';
|
|
@@ -289,8 +298,9 @@
|
|
| 289 |
},
|
| 290 |
async fetchProfileInfo() {
|
| 291 |
try {
|
| 292 |
-
const user = await
|
| 293 |
-
|
|
|
|
| 294 |
await this.checkAllowlist(user.email);
|
| 295 |
} catch (error) {
|
| 296 |
console.error("Error fetching profile info:", error);
|
|
@@ -324,4 +334,4 @@
|
|
| 324 |
app.mount('#app');
|
| 325 |
</script>
|
| 326 |
</body>
|
| 327 |
-
</html>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Multi Agent Research</title>
|
| 7 |
+
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
|
| 8 |
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
| 10 |
<style>
|
|
|
|
| 167 |
|
| 168 |
<script>
|
| 169 |
const { createApp } = Vue;
|
| 170 |
+
const { createClient } = supabase;
|
| 171 |
|
| 172 |
+
const supabaseClient = createClient('https://ftqmmutydpjseodidugl.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZ0cW1tdXR5ZHBqc2VvZGlkdWdsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTQzMTE2MzQsImV4cCI6MjAyOTg4NzYzNH0.2h1uLIPCKrwF8f9enRChU_Q2qkhoQlR4gwlehL-h0a4');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
function setCookie(name, value, days) {
|
| 175 |
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
|
|
| 205 |
async checkAuth() {
|
| 206 |
try {
|
| 207 |
console.log("Checking authentication");
|
| 208 |
+
const { data: { session }, error } = await supabaseClient.auth.getSession();
|
| 209 |
+
if (error) throw error;
|
| 210 |
console.log("Session:", session);
|
| 211 |
return session;
|
| 212 |
} catch (error) {
|
|
|
|
| 235 |
console.log("Stored app_data and current_page in cookies", this.appData, this.currentPage);
|
| 236 |
} else {
|
| 237 |
console.log("Access denied");
|
| 238 |
+
this.error = `Access Denied: Your email (${email}) is not on the allowlist. Server message: ${response.data.message || 'No additional information provided.'}`;
|
| 239 |
}
|
| 240 |
} catch (error) {
|
| 241 |
console.error("Error checking allowlist:", error);
|
| 242 |
+
let errorMessage = 'An error occurred while checking access.';
|
| 243 |
+
if (error.response) {
|
| 244 |
+
// The request was made and the server responded with a status code
|
| 245 |
+
// that falls out of the range of 2xx
|
| 246 |
+
errorMessage += ` Server responded with status ${error.response.status}.`;
|
| 247 |
+
if (error.response.data && error.response.data.message) {
|
| 248 |
+
errorMessage += ` Message: ${error.response.data.message}`;
|
| 249 |
+
}
|
| 250 |
+
} else if (error.request) {
|
| 251 |
+
// The request was made but no response was received
|
| 252 |
+
errorMessage += ' No response received from server.';
|
| 253 |
+
} else {
|
| 254 |
+
// Something happened in setting up the request that triggered an Error
|
| 255 |
+
errorMessage += ` Error message: ${error.message}`;
|
| 256 |
+
}
|
| 257 |
+
this.error = `Error for email (${email}): ${errorMessage}`;
|
| 258 |
} finally {
|
| 259 |
console.log("Setting loading to false");
|
| 260 |
this.loading = false;
|
|
|
|
| 279 |
document.body.appendChild(loadingElement);
|
| 280 |
|
| 281 |
try {
|
| 282 |
+
const { error } = await supabaseClient.auth.signOut();
|
| 283 |
+
if (error) throw error;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
// Clear cookies
|
| 286 |
document.cookie = 'app_data=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Strict';
|
|
|
|
| 298 |
},
|
| 299 |
async fetchProfileInfo() {
|
| 300 |
try {
|
| 301 |
+
const { data: { user }, error } = await supabaseClient.auth.getUser();
|
| 302 |
+
if (error) throw error;
|
| 303 |
+
this.userName = user.user_metadata.full_name || user.email || 'User';
|
| 304 |
await this.checkAllowlist(user.email);
|
| 305 |
} catch (error) {
|
| 306 |
console.error("Error fetching profile info:", error);
|
|
|
|
| 334 |
app.mount('#app');
|
| 335 |
</script>
|
| 336 |
</body>
|
| 337 |
+
</html>
|