Skip to content

Commit

Permalink
fix: logout issue #509
Browse files Browse the repository at this point in the history
fixed logout issue
  • Loading branch information
jasurobo committed Jan 17, 2022
1 parent f1d6e75 commit 06fccf0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion component/profile/ProfileDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function ProfileDetails({ userData, userCurrentLogin }) {
className={`rounded p-4 h-full text-gray-700 relative ${Profilestyles?.bg_red_110} overflow-auto`}
>
<div className="flex">
{`${userData.id}` === userCurrentLogin && (
{`${userData.id}` === `${userCurrentLogin}` && (
<Link href="/settings">
<a>
<img
Expand Down
19 changes: 10 additions & 9 deletions pages/u/[username].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState, useEffect } from "react";
import Head from "next/head";

import Navbar from "../../component/profile/Navbar";
import { getCookieValue } from "../../lib/cookie";
import Activity from "../../component/profile/Activity";
Expand All @@ -12,10 +11,8 @@ import LuckEgg from "../../component/profile/LuckEgg";
import SiteHeader from "../../component/layout/SiteHeader/SiteHeader";
import UserService from "../../services/UserService";
import PostService from "../../services/PostService";
import Cookies from "universal-cookie";
import Profilestyles from "../../styles/Profile.module.css";
import SkillSet from "../../component/profile/SkillSet";
import notify from "../../lib/notify";

export async function getServerSideProps(context) {
try {
Expand All @@ -29,7 +26,6 @@ export async function getServerSideProps(context) {
const userId = cookie.id;
const username = context.params.username;

// let isThisUserTheCurrentLoggedIn = false;
const data = await UserService.getUserByUsername(username);
return {
props: {
Expand All @@ -38,18 +34,22 @@ export async function getServerSideProps(context) {
}
};
} else {
//user logout from user profile
const data = await UserService.getUserByUsername(context.params.username);
return {
redirect: {
permanent: false,
destination: "/404"
}
props : {
userData : data?.data,
userCurrentLogin: 0
}
};
}
} else {
const data = await UserService.getUserByUsername(context.params.username);
return {
props : {
userData : data?.data
userData : data?.data,
userCurrentLogin: data.data.id

}
};
}
Expand All @@ -66,6 +66,7 @@ export async function getServerSideProps(context) {
}

export default function Username({ userData, userCurrentLogin }) {
console.log(userCurrentLogin);
const [currentNav, setCurrentNav] = useState("profile");
const [newBlogs, setNewBlogs] = useState();
const [postsCount, setPostsCount] = useState();
Expand Down
4 changes: 1 addition & 3 deletions services/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ async function changePassword(passwords, userCookie) {
}

async function logout() {
// console.log("logout");
try {
await axios.post(`${logoutUrl}`, {});
} catch {}
window.localStorage.removeItem("progress");
sessionStorage.removeItem("userNullcast");
document.cookie = "userNullcast=''; Max-Age=0;";
// console.log(router);
document.cookie = "userNullcast=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
if (router.pathname === "/posts" || router.pathname === "/posts/write") {
router.push("/");
} else if (router.pathname !== "/login") {
Expand Down

0 comments on commit 06fccf0

Please sign in to comment.