Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from web3community/redirect
Browse files Browse the repository at this point in the history
fix: user canno't access creation without login
  • Loading branch information
KukretiShubham authored Dec 14, 2021
2 parents 05c9acc + 0f23ee7 commit 8fbe761
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 23 deletions.
3 changes: 2 additions & 1 deletion components/nav/dashboard-navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -182,6 +182,7 @@ function Navbar({ router, headerName }) {
<Disclosure.Panel className="md:hidden">
<div className="px-2 pt-2 pb-3 space-y-1 sm:px-3">
{navigation.map((item) => (

<Disclosure.Button
key={item.name}
as="a"
Expand Down
9 changes: 8 additions & 1 deletion pages/dashboard/create-nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
getSession,
signIn,
signOut,
useSession
} from 'next-auth/client';
import {
LoginIcon
Expand Down Expand Up @@ -74,6 +73,14 @@ export const getServerSideProps = async (context) => {
};
}
}
// 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 {
Expand Down
27 changes: 10 additions & 17 deletions pages/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
};
}
}

};
27 changes: 27 additions & 0 deletions pages/dashboard/my-creations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,3 +100,27 @@ export default function MyCreation() {
</Layout>
)
}

// 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
}
};
};
30 changes: 30 additions & 0 deletions pages/dashboard/my-nfts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,3 +78,27 @@ export default function MyAssets() {
</Layout>
)
}

// 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
}
};
};
9 changes: 5 additions & 4 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/outline/
Expand All @@ -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 ----
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8fbe761

Please sign in to comment.