Skip to content

Latest commit

 

History

History
65 lines (61 loc) · 2.92 KB

File metadata and controls

65 lines (61 loc) · 2.92 KB
layout base
title Book Connect
search_exclude true
menu nav/home.html
<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.