Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logout functionality #296

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion public/css/profile.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,24 @@ body{
section{
display: flex;
}

#box1 {
width: 100%;
max-width: 500px;
padding: 12px;
border-radius: 8px;
text-align: center;
font-size: 12px;
position: absolute;
top: 10%;
left: 50%;
transform: translateX(-50%);
}
#box1 {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
display: none;
}
:root{
--primary-color: #fff;
--secondary-color: #0e0e0e;
Expand Down
34 changes: 13 additions & 21 deletions public/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<li><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Home</li>
<li><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>About Us</li>
<li onclick="view_result()"><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>View Result</li>
<li id="logoutBtn"><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Log Out</li>
<li onclick="handleLogout()"><i class="fa-solid fa-code" style="padding: 0px 14px;"></i>Log Out</li>
<li>
<div class="gtranslate_wrapper"></div>
<script>
Expand Down Expand Up @@ -137,6 +137,9 @@ <h3 style="margin-left:3vw;font-size: 22px;">Edit Profile</h3>
</div>
</div>
</div>
<div id="box1">
<p>Logout Successfully...</p>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also increase the font-size of the message

</div>
</section>
<style>
.dualBtns {
Expand Down Expand Up @@ -235,27 +238,16 @@ <h3 style="margin-left:3vw;font-size: 22px;">Edit Profile</h3>
}
}
fetchdata()
const handleLogout = async () => {
try {
const token = localStorage.getItem('token'); // Retrieve the token from storage
const response = await fetch('/logout', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`, // Send the token if needed
},
});

if (response.ok) {
localStorage.removeItem('token'); // Remove the token from storage
window.location.href = '/';
} else {
console.error("Logout failed:", response.statusText);
}
} catch (error) {
console.error("Logout error:", error);
}
const handleLogout = () => {
const result1 = document.getElementById('box1');
result1.style.display = 'block';
localStorage.clear();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using clear function use removeItem for removing the token

console.log("logout");
setTimeout(() => {
window.location.href = 'index.html';
}, 2000)
};
document.getElementById('logoutBtn').addEventListener('click', handleLogout);

function hide() {
document.body.classList.toggle("dark-theme");
const regularicon = document.getElementById('regular')
Expand Down
48 changes: 29 additions & 19 deletions public/stk_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,24 @@
width: 20vw;
display: block;
}

#box1 {
width: 100%;
max-width: 500px;
padding: 12px;
border-radius: 8px;
text-align: center;
font-size: 12px;
position: absolute;
top: -5%;
left: 50%;
transform: translateX(-50%);
}
#box1 {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
display: none;
}
section {
margin: 0vh 10vw;
background-color: white;
Expand Down Expand Up @@ -210,6 +227,9 @@ <h2 class="mb-0">
</div>
</div>
</div>
<div id="box1">
<p>Logout Successfully...</p>
</div>
</section>

<div style="position: absolute; top: 30px; left: 30px;" class="gtranslate_wrapper"></div>
Expand All @@ -233,25 +253,15 @@ <h2 class="mb-0">
integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
crossorigin="anonymous"></script>
<script>
const handleLogout = async () => {
try {
const token = localStorage.getItem('token'); // Retrieve the token from storage
const response = await fetch('/logout', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`, // Send the token if needed
},
});
const handleLogout = () => {
const result1 = document.getElementById('box1');
result1.style.display = 'block';
localStorage.clear();
console.log("logout");
setTimeout(() => {
window.location.href = 'index.html';
}, 2000)

if (response.ok) {
localStorage.removeItem('token'); // Remove the token from storage
window.location.href = '/';
} else {
console.error("Logout failed:", response.statusText);
}
} catch (error) {
console.error("Logout error:", error);
}
};
document.getElementById('logoutBtn').addEventListener('click', handleLogout);
document.getElementById('darkModeIcon').onclick = function () {
Expand Down