-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add changes to logged in function to run each time user logs in/out t…
…o alter navbar. Relates #44. Co-authored-by: Giovanna <[email protected]>
- Loading branch information
Showing
6 changed files
with
27 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
const header = document.querySelector("#navBar"); | ||
const token = localStorage.getItem("token"); | ||
|
||
function isLoggedIn() { | ||
const link1 = document.createElement("a"); | ||
const link2 = document.createElement("a"); | ||
if (token) { | ||
link1.href = "/log-out"; | ||
link1.textContent = "Log Out"; | ||
link1.setAttribute("id", "logOutBtn"); | ||
link2.href = "/user"; // View my dogs | ||
link2.textContent = "View My Dogs"; | ||
link2.setAttribute("id", "viewMyDogsBtn"); | ||
} else { | ||
const link1 = document.querySelector("#link1"); | ||
const link2 = document.querySelector("#link2"); | ||
const token = localStorage.getItem("token"); | ||
if (!token) { | ||
link1.href = "/log-in"; | ||
link1.textContent = "Log In"; | ||
link1.setAttribute("id", "logInBtn"); | ||
link2.href = "/sign-up"; | ||
link2.textContent = "Sign Up"; | ||
link2.setAttribute("id", "signUpBtn"); | ||
} else { | ||
link1.href = "/log-out"; | ||
link1.textContent = "Log Out"; | ||
link2.href = "/user"; // View my dogs | ||
link2.textContent = "View My Dogs"; | ||
} | ||
|
||
header.append(link1); | ||
header.append(link2); | ||
} | ||
|
||
isLoggedIn(); | ||
export default isLoggedIn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import query from "../query.js"; | ||
const app = document.querySelector("#app"); | ||
import isLoggedIn from "../auth-status.js"; | ||
|
||
// const html; /*html template literal*/ | ||
|
||
function logOut() { | ||
const button = document.querySelector("#logOutBtn"); | ||
function logOut({redirect}) { | ||
window.localStorage.removeItem("id"); | ||
window.localStorage.removeItem("token"); | ||
isLoggedIn(); | ||
redirect("/"); | ||
} | ||
|
||
export default logOut; | ||
|
||
function home({redirect}) { | ||
const token = localStorage.getItem("token"); | ||
if (!token) { | ||
app.innerHTML = loggedOut; | ||
} else { | ||
app.innerHTML = loggedIn; | ||
app.querySelector("#logOut").addEventListener("click", () => { | ||
window.localStorage.removeItem("token"); | ||
redirect("/"); | ||
}); | ||
} | ||
} |