File tree Expand file tree Collapse file tree 4 files changed +22
-3
lines changed
services/question-service Expand file tree Collapse file tree 4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import {
25
25
SearchOutlined ,
26
26
} from "@ant-design/icons" ;
27
27
import "./styles.scss" ;
28
- import { useEffect , useState } from "react" ;
28
+ import { useEffect , useState , useLayoutEffect } from "react" ;
29
29
import {
30
30
DeleteQuestion as DeleteQuestionByDocref ,
31
31
GetQuestions ,
@@ -42,6 +42,8 @@ import {
42
42
import Link from "next/link" ;
43
43
import TextArea from "antd/es/input/TextArea" ;
44
44
import { title } from "process" ;
45
+ import { isAuthenticated } from "@/utils/Auth" ;
46
+ import { redirect } from 'next/navigation' ;
45
47
46
48
/**
47
49
* defines the State of the page whe a user is deleing an object. Has 3 general states:
@@ -117,6 +119,13 @@ export default function Home() {
117
119
// State for refreshing data
118
120
const [ refresh , setRefresh ] = useState ( false ) ;
119
121
122
+ useLayoutEffect ( ( ) => {
123
+ const isAuth = isAuthenticated ;
124
+ if ( ! isAuth ) {
125
+ redirect ( "/login" )
126
+ }
127
+ } , [ ] )
128
+
120
129
const handleEditClick = ( index : number , question : Question ) => {
121
130
// Open the modal for the specific question
122
131
const updatedModals =
Original file line number Diff line number Diff line change @@ -25,12 +25,14 @@ import {
25
25
CheckCircleOutlined ,
26
26
} from "@ant-design/icons" ;
27
27
import "./styles.scss" ;
28
- import { useEffect , useState } from "react" ;
28
+ import { useEffect , useState , useLayoutEffect } from "react" ;
29
29
import { Question , GetSingleQuestion } from "../../services/question" ;
30
30
import React from "react" ;
31
31
import TextArea from "antd/es/input/TextArea" ;
32
32
import { useSearchParams } from "next/navigation" ;
33
33
import { ProgrammingLanguageOptions } from "@/utils/SelectOptions" ;
34
+ import { isAuthenticated } from "@/utils/Auth" ;
35
+ import { redirect } from 'next/navigation' ;
34
36
35
37
export default function Home ( ) {
36
38
const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ; // Store the states related to table's loading
@@ -58,6 +60,13 @@ export default function Home() {
58
60
const [ description , setDescription ] = useState < string | undefined > ( undefined ) ;
59
61
const [ selectedItem , setSelectedItem ] = useState ( "python" ) ; // State to hold the selected language item
60
62
63
+ useLayoutEffect ( ( ) => {
64
+ const isAuth = isAuthenticated ;
65
+ if ( ! isAuth ) {
66
+ redirect ( "/login" )
67
+ }
68
+ } , [ ] )
69
+
61
70
// When code editor page is initialised, fetch the particular question, and display in code editor
62
71
useEffect ( ( ) => {
63
72
if ( ! isLoading ) {
Original file line number Diff line number Diff line change
1
+ export const isAuthenticated = true ;
Original file line number Diff line number Diff line change 1
1
# please add all private keys here
2
-
2
+ cs3219-g24-staging-firebase-adminsdk-suafv-9c0d1b2299.json
3
3
cs3219-g24-firebase-adminsdk-9cm7h-b1675603ab.json
4
4
You can’t perform that action at this time.
0 commit comments