Skip to content

Commit

Permalink
added firebase stuff login feature, mini link checker, soon minilink …
Browse files Browse the repository at this point in the history
…redirect
  • Loading branch information
maddox05 committed Sep 9, 2023
1 parent 3cf31a3 commit fa692d2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Link Minifier</title>
<script defer src="server/server.js" type="module"></script>

<button id="button1">Call thing with thing</button>

</head>
<body>
Expand Down
72 changes: 68 additions & 4 deletions public/server/server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Purpose: Firebase configuration and initialization
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-analytics.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-firestore.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-auth.js";

import { getFirestore, collection, serverTimestamp, addDoc, query, onSnapshot, getDocs, orderBy } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-firestore.js";
import { getAuth, GoogleAuthProvider, signInWithPopup, onAuthStateChanged, signOut } from "https://www.gstatic.com/firebasejs/10.3.1/firebase-auth.js";

//treating this file like a nodejs file

import { firebaseConfig } from "../private/firebase_config.js";

Expand All @@ -14,4 +14,68 @@ const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore(app);
const auth = getAuth(app);
console.log("Firebase initialized");
console.log("Firebase initialized");

const what_collection = collection(db, "mini_links"); // collection, (database, collection name) // what collection of documents I want to look at


function log_in(){ // to go to frontend
const google_provider = new GoogleAuthProvider();
signInWithPopup(auth, google_provider)
.then(result =>{
const user = result.user;
})
.catch(error =>{
console.log("error",error);
});
}
function mini_link_checker(normal_link, user_mini_link, userid){
if(userid !== null){
const query = query(what_collection, orderBy("timestamp", "desc"));
getDocs(query)
.then((snapshot) =>{
if(snapshot.docs.includes(user_mini_link)){ // if docs alr have minilink in it
return false;
}
else{// else add the doc
const data ={
normal_link: normal_link,
mini_link: user_mini_link,
userid: userid,
timestamp: serverTimestamp()
}
addDoc(what_collection, data)
.then((result)=>{
console.log("sent!")
return true;
})
.catch((error)=>{
console.log(error)
return false;
})

}
})
.catch((error)=>{
console.log(error)
return false;
}
)
//technically should check if link is valid

}
else{
return false;
}
// checks if mini link is makeable and if It's makeable than add it
// returns true if link was created
// returns false if link was not created
}
function mini_link_redirect(){
if(window.location.href.includes("maddox.boo/")){
//redirect
}
else{
console.log("not valid")
}
}

0 comments on commit fa692d2

Please sign in to comment.