diff --git a/components/nav/dashboard-navbar.js b/components/nav/dashboard-navbar.js index d3df199..70b5cb3 100644 --- a/components/nav/dashboard-navbar.js +++ b/components/nav/dashboard-navbar.js @@ -112,7 +112,7 @@ function Navbar({ router, headerName }) { className={classNames( router.asPath == item.href ? 'bg-purple-700 text-white' - : 'text-white hover:bg-purple-500 hover:bg-opacity-75', + : 'text-white sm:text-center hover:bg-purple-500 hover:bg-opacity-75', 'px-3 py-2 rounded-md text-sm font-medium' )} aria-current={item.current ? 'page' : undefined} @@ -182,6 +182,7 @@ function Navbar({ router, headerName }) {
{navigation.map((item) => ( + { }; } } + // Redirect the user if not logged to github + else { + + // note: we should trigger an alert if the user isn't connect + return { + redirect: { destination: '/dashboard', permanent: false } + } + } return { diff --git a/pages/dashboard/index.js b/pages/dashboard/index.js index 8a1fc32..9074010 100644 --- a/pages/dashboard/index.js +++ b/pages/dashboard/index.js @@ -63,31 +63,24 @@ export default function Home({ session }) { ) } -// Get the github session at the runtime of the app + +// Get the github session export const getServerSideProps = async (context) => { // Get github login const session = await getSession(context) if (session) { - var login = session.profile.login; - - if (login) { - const res = await fetch('https://api.github.com/users/' + login + '/repos'); - const reposList = await res.json(); - - return { - props: { - session, - reposList - }, - }; - } + return { + props: { + session, + }, + }; } - return { props: { session - }, - }; + } + } + }; diff --git a/pages/dashboard/my-creations.js b/pages/dashboard/my-creations.js index a3296f7..074e0d8 100644 --- a/pages/dashboard/my-creations.js +++ b/pages/dashboard/my-creations.js @@ -2,6 +2,9 @@ import { ethers } from 'ethers' import { useEffect, useState } from 'react' import axios from 'axios' import Web3Modal from "web3modal" +import { + getSession, +} from 'next-auth/client'; import { nftmarketaddress, nftaddress @@ -97,3 +100,27 @@ export default function MyCreation() { ) } + +// Get the github session at the runtime of the app +export const getServerSideProps = async (context) => { + + // Get github login + const session = await getSession(context) + if (session) { + // Do something... + } + // Redirect the user if not logged to github + else { + + // note: we should trigger an alert if the user isn't connect + return { + redirect: { destination: '/dashboard', permanent: false } + } + } + + return { + props: { + session + } + }; +}; diff --git a/pages/dashboard/my-nfts.js b/pages/dashboard/my-nfts.js index fc9cf37..78066c4 100644 --- a/pages/dashboard/my-nfts.js +++ b/pages/dashboard/my-nfts.js @@ -2,6 +2,12 @@ import { ethers } from 'ethers' import { useEffect, useState } from 'react' import axios from 'axios' import Web3Modal from "web3modal" +import { + getSession, + signIn, + signOut, + useSession +} from 'next-auth/client'; import { nftmarketaddress, nftaddress @@ -72,3 +78,27 @@ export default function MyAssets() { ) } + +// Get the github session at the runtime of the app +export const getServerSideProps = async (context) => { + + // Get github login + const session = await getSession(context) + if (session) { + // Do something... + } + // Redirect the user if not logged to github + else { + + // note: we should trigger an alert if the user isn't connect + return { + redirect: { destination: '/dashboard', permanent: false } + } + } + + return { + props: { + session + } + }; +}; \ No newline at end of file diff --git a/pages/index.js b/pages/index.js index afe2c33..b56f2a0 100644 --- a/pages/index.js +++ b/pages/index.js @@ -28,7 +28,9 @@ import { SupportIcon, ViewGridIcon, XIcon, - LogoutIcon + LogoutIcon, + LoginIcon, + } from '@heroicons/react/outline'; // If you need another icon, just add his name in the list below // from https://unpkg.com/browse/@heroicons/react@1.0.5/outline/ @@ -43,7 +45,8 @@ const home = ({ session }) => { // Mobile menu data const mobileMenu = [ - { name: 'Dashboard', icon: CogIcon, href:'/dashboard' } + { name: 'Login', icon: LoginIcon, href: '/login'}, + { name: 'Marketplace', icon: PlayIcon, href:'/dashboard' } ] // ---- METAMASK ---- @@ -265,8 +268,6 @@ export const getServerSideProps = async (context) => { // else console.log("User is logged in to MetaMask"); // }); - console.log("session", session) - return { props: { session,