Skip to content

Commit

Permalink
[FAIR-85] refactoring authentication feature
Browse files Browse the repository at this point in the history
  • Loading branch information
xdemocle committed Dec 17, 2021
1 parent 0fee086 commit a57a1d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions components/Topbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import DappIcon from 'assets/icons/dapp.svg';
import useUser from 'hooks/useUser';

const Topbar = () => {
const { user, logout } = useUser();
const { user, isAuthenticated } = useUser();

return (
<header
Expand All @@ -25,18 +25,19 @@ const Topbar = () => {

<div className="flex-grow flex items-center justify-between">
<div className="pl-2">
<Dropdown>FairOS (Server)</Dropdown>
{isAuthenticated && <Dropdown>FairOS (Server)</Dropdown>}
</div>

<div className="flex items-center mr-8">
<SearchBar />
{isAuthenticated && <SearchBar />}

<Link href="/">
<a>
<DappIcon className="mx-3" />
</a>
</Link>
{!!user && (

{isAuthenticated && (
<>
<Link href="/">
<a className="mx-3 text-purple">Activity</a>
Expand Down
15 changes: 8 additions & 7 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import Router from 'next/router';
import { useEffect } from 'react';

const Home: NextPage = () => {
const { user } = useUser();
const { isAuthenticated } = useUser();

useEffect(() => {
if (!user) {
if (!isAuthenticated) {
Router.push('/login');
}
}, [user]);
}, [isAuthenticated]);

return (
<Layout>
<h1 className="text-center">Fairdrive</h1>
{!user && <h3 className="text-center">user loggeout</h3>}
</Layout>
isAuthenticated && (
<Layout>
<h1 className="text-center">Fairdrive</h1>
</Layout>
)
);
};

Expand Down

0 comments on commit a57a1d7

Please sign in to comment.