Files changed (2) hide show
  1. gemini.js +11 -0
  2. scriptsfirebase.js +58 -0
gemini.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export async function askGemini(prompt) {
2
+ const GEMINI_API_KEY = import.meta.env.GEMINI_API_KEY;
3
+ const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${GEMINI_API_KEY}`, {
4
+ method: "POST",
5
+ headers: { "Content-Type": "application/json" },
6
+ body: JSON.stringify({
7
+ contents: [{ role: "user", parts: [{ text: prompt }] }]
8
+ })
9
+ });
10
+ return await response.json();
11
+ }
scriptsfirebase.js ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ initializeApp
3
+ } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-app.js";
4
+ import {
5
+ getAuth,
6
+ onAuthStateChanged,
7
+ signOut,
8
+ signInAnonymously,
9
+ GoogleAuthProvider,
10
+ signInWithPopup
11
+ } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
12
+
13
+ const firebaseConfig = {
14
+ apiKey: import.meta.env.FIREBASE_API_KEY,
15
+ authDomain: import.meta.env.FIREBASE_AUTH_DOMAIN,
16
+ projectId: import.meta.env.FIREBASE_PROJECT_ID,
17
+ storageBucket: import.meta.env.FIREBASE_STORAGE_BUCKET,
18
+ messagingSenderId: import.meta.env.FIREBASE_MESSAGING_SENDER_ID,
19
+ appId: import.meta.env.FIREBASE_APP_ID,
20
+ measurementId: import.meta.env.FIREBASE_MEASUREMENT_ID
21
+ };
22
+
23
+ const app = initializeApp(firebaseConfig);
24
+ const auth = getAuth(app);
25
+
26
+ const loginBtn = document.getElementById("loginAnonButton");
27
+ const logoutBtn = document.getElementById("logoutButton");
28
+
29
+ loginBtn.addEventListener("click", async () => {
30
+ try {
31
+ const provider = new GoogleAuthProvider();
32
+ await signInWithPopup(auth, provider);
33
+ } catch (err) {
34
+ console.error("Error al iniciar sesión:", err);
35
+ }
36
+ });
37
+
38
+ document.getElementById("anonymousLoginButton").addEventListener("click", async () => {
39
+ try {
40
+ await signInAnonymously(auth);
41
+ } catch (error) {
42
+ console.error(error);
43
+ }
44
+ });
45
+
46
+ logoutBtn.addEventListener("click", async () => {
47
+ await signOut(auth);
48
+ });
49
+
50
+ onAuthStateChanged(auth, (user) => {
51
+ if (user) {
52
+ document.getElementById("loginAnonButton").style.display = "none";
53
+ document.getElementById("logoutButton").style.display = "block";
54
+ } else {
55
+ document.getElementById("loginAnonButton").style.display = "block";
56
+ document.getElementById("logoutButton").style.display = "none";
57
+ }
58
+ });