You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<script type="module">
import {
pythonURI,
fetchOptions,
} from "{{site.baseurl}}/assets/js/api/config.js";
document.addEventListener("DOMContentLoaded", () => {
getCredentials() // Call the function to get credentials
.then((data) => {
if (data) {
//IF DATA THEN THE USER IS AUTHENTICATED/LOGGED IN
console.log("LOGGED IN");
window.location.href = "{{site.baseurl}}/profile";
}
})
.catch((err) => {
// General error handler
console.error("Error fetching credentials: ", err);
});
});
function getCredentials() {
const URL = pythonURI + "/api/user";
return fetch(URL, fetchOptions)
.then((response) => {
// API response handler
if (response.status !== 200) {
console.error("HTTP status code: " + response.status);
return null; // prepares to stop the chain by returning null.
}
return response.json(); // plans to continue the chain with the data.
})
.then((data) => {
// Data handler from the previous promise
if (data === null) return null; // stops the chain, returns null.
console.log(data); // logs data with should contain uid, name, etc.
return data; // returns data to caller
})
.catch((err) => {
// General error handler
console.error("Fetch error: ", err);
return null;
});
}
</script>
Connect Through Books
Join the ultimate hub for book lovers—track your reading journey, connect with fellow readers, and discover your next favorite book.