Skip to content

Commit 6558d4a

Browse files
committedDec 16, 2023
debugging token data
1 parent dacc7a3 commit 6558d4a

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed
 

‎.env.sample

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
VITE_API_ENDPOINT=""
2-
VITE_OAUTH_CLIENT_ID=""
2+
VITE_OAUTH_CLIENT_ID=""
3+
VITE_NODE_ENV=development

‎src/App.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Testcase from './screens/Testcase'
1010
import Uzrast from './screens/Uzrast'
1111
import About from './components/Informations'
1212
import { checkUserCategories } from './api/repository'
13+
import { logger } from './utils/logger'
1314

1415
export type UserType = {
1516
name: string
@@ -46,17 +47,17 @@ function App() {
4647
const [categoryData, setCategoryData] = useState<Record<string, string> | undefined>(undefined)
4748

4849
useEffect(() => {
49-
console.log('token: ', token)
50+
logger('token: ', token)
5051
}, [token])
5152

5253
useEffect(() => {
53-
console.log('user: ', user)
54+
logger('user: ', user)
5455

5556
if (!categoryData?.[user?.email || '']) {
5657
checkUserCategories(['none'])
5758
.then(res => res.json())
5859
.then(userCategoryData => {
59-
console.log('checkUserCategories response: ', userCategoryData)
60+
logger('checkUserCategories response: ', userCategoryData)
6061
setCategoryData(userCategoryData)
6162
})
6263
}
@@ -69,7 +70,7 @@ function App() {
6970
checkUserCategories(['none'])
7071
.then(res => res.json())
7172
.then(userCategoryData => {
72-
console.log('checkUserCategories response: ', userCategoryData)
73+
logger('checkUserCategories response: ', userCategoryData)
7374
setCategoryData(userCategoryData)
7475

7576
extractUser(pureToken)

‎src/api/api.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { XFER_KONTESTIS_ORG_ID } from '@/utils/kontestis'
22

3-
export const JSON_HEADER = {
4-
// fali authorization header
5-
Authorization: `${localStorage.getItem('SavedLoginToken')}`,
6-
'X-Kontestis-Org-Id': XFER_KONTESTIS_ORG_ID,
7-
'Content-Type': 'application/json',
3+
export const JSON_HEADER = () => {
4+
return {
5+
// fali authorization header
6+
Authorization: `${localStorage.getItem('SavedLoginToken')}`,
7+
'X-Kontestis-Org-Id': XFER_KONTESTIS_ORG_ID,
8+
'Content-Type': 'application/json',
9+
}
810
}

‎src/api/repository.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { INVITE_CODE, getContestID, getInviteCode } from '@/utils/kontestis'
55
export const addToContest = () => {
66
return fetch(R.joinContest(), {
77
method: 'POST',
8-
headers: JSON_HEADER,
8+
headers: JSON_HEADER(),
99
body: JSON.stringify({
1010
join_code: INVITE_CODE,
1111
}),
@@ -17,7 +17,7 @@ export const addToContestSpecific = (number: number) => {
1717

1818
return fetch(R.joinContest(), {
1919
method: 'POST',
20-
headers: JSON_HEADER,
20+
headers: JSON_HEADER(),
2121
body: JSON.stringify({
2222
join_code: inv_code,
2323
}),
@@ -66,7 +66,7 @@ export const submitSolution = (problemId: string, code: string) => {
6666
// console.log('submitSolution', problemId, code.substring(0, 100))
6767
return fetch(R.submissionOfSolution(problemId), {
6868
method: 'POST',
69-
headers: JSON_HEADER,
69+
headers: JSON_HEADER(),
7070
body: JSON.stringify({
7171
language: 'output-only',
7272
code: code,
@@ -79,7 +79,7 @@ export type possibleProgrammingLanguages = 'python' | 'c' | 'cpp' | 'go' | 'rust
7979
export const submitSolution2 = (problemId: string, code: string, language: string) => {
8080
return fetch(R.submissionOfSolution(problemId), {
8181
method: 'POST',
82-
headers: JSON_HEADER,
82+
headers: JSON_HEADER(),
8383
body: JSON.stringify({
8484
language: language,
8585
code: code,
@@ -90,6 +90,6 @@ export const submitSolution2 = (problemId: string, code: string, language: strin
9090
export const getLeaderboard = (problemNumber: number) => {
9191
return fetch(R.leaderboard(getContestID(problemNumber)), {
9292
method: 'GET',
93-
headers: JSON_HEADER,
93+
headers: JSON_HEADER(),
9494
})
9595
}

‎src/components/Header.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Dispatch, SetStateAction, useContext } from 'react'
66
import UserDropdown from './UserDropdown'
77
import { addToAllContests } from '@/api/repository'
88
import LeaderboardDropdownIcon from '@/screens/leaderboard/LeaderboardDropdownIcon'
9+
import { logger } from '@/utils/logger'
910

1011
type HeaderType = {
1112
setToken: Dispatch<SetStateAction<string>>
@@ -39,7 +40,11 @@ const Header = ({ setToken, setIsLoggedIn }: HeaderType) => {
3940
return config
4041
})
4142
})
42-
.then(() => addToAllContests())
43+
.then(() => {
44+
logger('adding to all contests...')
45+
logger('token: ', localStorage.getItem('SavedLoginToken'))
46+
addToAllContests()
47+
})
4348
}
4449

4550
return (

‎src/screens/Testcase.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Testcase = () => {
1515
.then(text => {
1616
fetch(`https://api.kontestis.ac/api/problem/${ids[0]}/cluster/${ids[1]}/testcase/${ids[2]}`, {
1717
method: 'PATCH',
18-
headers: JSON_HEADER,
18+
headers: JSON_HEADER(),
1919
body: JSON.stringify({
2020
input: text,
2121
}),

‎src/utils/logger.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
export const logger = (message: any, ...other: any[]) => {
3+
if (import.meta.env.VITE_NODE_ENV === 'development') {
4+
console.log(message, ...other)
5+
}
6+
}

0 commit comments

Comments
 (0)
Please sign in to comment.