Skip to content

Commit 84550bd

Browse files
authored
Merge pull request #198 from ctfguide-tech/dev
merge
2 parents 50a7594 + 002cad6 commit 84550bd

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/pages/_app.jsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import { Context } from '../context';
77
import { useEffect, useState } from 'react';
88
import request from '@/utils/request';
99
import { Analytics } from "@vercel/analytics/react"
10+
import { usePathname, useRouter } from 'next/navigation';
11+
1012

1113
export default function App({ Component, pageProps }) {
1214
const [username, setUsername] = useState('');
1315
const [role, setRole] = useState('');
1416
const [accountType, setAccountType] = useState('');
1517
const [profilePic, setProfilePic] = useState('');
1618
const [points, setPoints] = useState(0);
19+
const path = usePathname();
20+
const router = useRouter();
1721

1822
const appState = {
1923
role, setRole,
@@ -26,7 +30,14 @@ export default function App({ Component, pageProps }) {
2630
const fetchUser = async () => {
2731
const url = process.env.NEXT_PUBLIC_API_URL + "/account";
2832
const user = await request(url, "GET", null);
29-
console.log(user);
33+
34+
if(user && user.error && user.error === "Not authorized") {
35+
const pathNames = ["/", "/login", "/careers", "/register",
36+
"/onboarding", "/forgot-password", "/education", "/userrs",
37+
"/privacy-policy","/404", "/terms-of-service", "/learn"];
38+
if(!pathNames.includes(path)) router.push("/login");
39+
}
40+
3041
if (user && user.username) {
3142
setRole(user.role);
3243
setUsername(user.username);

src/pages/users/[user].jsx

+26-16
Original file line numberDiff line numberDiff line change
@@ -944,20 +944,26 @@ export default function Create() {
944944
</span>
945945
)}
946946
{!ownUser && followedUser && (
947-
<span className="ml-2 text-lg text-white">
948-
<i
949-
className="fas fa-user-slash text-lg hover:text-gray-400"
950-
onClick={handleUnfollowUser}
947+
<button
948+
className="border rounded-sm border-neutral-500 ml-2 px-1 text-sm text-white hover:bg-neutral-600"
949+
onClick={handleUnfollowUser}>
950+
<i
951+
className="fas fa-user-slash text-xs"
951952
></i>
952-
</span>
953+
{' '}
954+
Unfollow
955+
</button>
953956
)}
954957
{!ownUser && !followedUser && (
955-
<span className="ml-2 text-lg text-white">
956-
<i
957-
className="fas fa-user-plus text-lg hover:text-gray-400"
958-
onClick={handleFollowUser}
958+
<button
959+
className="border rounded-sm border-neutral-500 ml-2 px-1 text-sm text-white hover:bg-neutral-600"
960+
onClick={handleFollowUser}>
961+
<i
962+
className="fas fa-user-plus text-xs"
959963
></i>
960-
</span>
964+
{' '}
965+
Follow
966+
</button>
961967
)}
962968
</h1>
963969
<p className="text-white">
@@ -976,21 +982,25 @@ export default function Create() {
976982
{user && (
977983
<>
978984
<span
979-
className="cursor-pointer font-bold hover:text-gray-400"
985+
className={`border border-neutral-500 rounded-sm px-2 py-1 cursor-pointer font-bold hover:bg-neutral-600 ${
986+
displayMode === 'followers' ? 'bg-neutral-500' : ''
987+
}`}
980988
onClick={() => setDisplayMode('followers')}
981989
>
982-
{' '}
983990
Followers
984-
</span>{' '}
991+
{' '}
985992
{followerNum || '0'}
993+
</span>
986994
<span
987-
className="ml-4 cursor-pointer font-bold hover:text-gray-400"
995+
className={`border border-neutral-500 rounded-sm px-2 py-1 ml-4 cursor-pointer font-bold hover:bg-neutral-600 ${
996+
displayMode === 'following' ? 'bg-neutral-500' : ''
997+
}`}
988998
onClick={() => setDisplayMode('following')}
989999
>
990-
{' '}
9911000
Following
992-
</span>{' '}
1001+
{' '}
9931002
{followingNum || '0'}
1003+
</span>
9941004
</>
9951005
)}
9961006
</p>

0 commit comments

Comments
 (0)