@@ -129,59 +129,6 @@ const AdminProjectRequestsPage = () => {
129129 } ;
130130
131131 // Admin verification effect
132- useEffect ( ( ) => {
133- const checkAdminAccess = async ( ) => {
134- console . log ( "Starting admin access check" ) ;
135- console . log ( "Is authenticated:" , isAuthenticated ) ;
136- console . log ( "User:" , user ) ;
137-
138- if ( ! isAuthenticated || ! user ) {
139- console . log ( "Not authenticated or no user, redirecting" ) ;
140- router . push ( '/' ) ;
141- return ;
142- }
143-
144- setIsCheckingAdmin ( true ) ;
145-
146- try {
147- console . log ( "Making admin verification request for user:" , user . id ) ;
148-
149- const response = await fetch ( '/api/admin/verify' , {
150- method : 'POST' ,
151- headers : {
152- 'Content-Type' : 'application/json' ,
153- } ,
154- body : JSON . stringify ( { userId : user . id } )
155- } ) ;
156-
157- console . log ( "Admin verification response status:" , response . status ) ;
158-
159- const responseData = await response . json ( ) ;
160- console . log ( "Admin verification response:" , responseData ) ;
161-
162- if ( response . ok && responseData . isAdmin ) {
163- console . log ( "Admin access verified" ) ;
164- setIsAdminVerified ( true ) ;
165- setAdminToken ( responseData . adminToken ) ; // Store the admin token
166- setError ( null ) ;
167- // Start fetching requests with the token directly since state hasn't updated yet
168- fetchRequests ( responseData . adminToken ) ;
169- } else {
170- console . log ( "Admin access denied:" , responseData . error ) ;
171- setError ( responseData . error || 'Access denied. Admin privileges required.' ) ;
172- setTimeout ( ( ) => router . push ( '/' ) , 3000 ) ;
173- }
174- } catch ( error ) {
175- console . error ( 'Admin verification failed:' , error ) ;
176- setError ( 'Failed to verify admin access. Please try again.' ) ;
177- setTimeout ( ( ) => router . push ( '/' ) , 3000 ) ;
178- } finally {
179- setIsCheckingAdmin ( false ) ;
180- }
181- } ;
182-
183- checkAdminAccess ( ) ;
184- } , [ isAuthenticated , user , router ] ) ;
185132
186133 const fetchRequests = async ( forceToken ?: string ) => {
187134 // If we have a force token, we're in the initial load after verification
@@ -270,6 +217,60 @@ const AdminProjectRequestsPage = () => {
270217 }
271218 } ;
272219
220+ useEffect ( ( ) => {
221+ const checkAdminAccess = async ( ) => {
222+ console . log ( "Starting admin access check" ) ;
223+ console . log ( "Is authenticated:" , isAuthenticated ) ;
224+ console . log ( "User:" , user ) ;
225+
226+ if ( ! isAuthenticated || ! user ) {
227+ console . log ( "Not authenticated or no user, redirecting" ) ;
228+ router . push ( '/' ) ;
229+ return ;
230+ }
231+
232+ setIsCheckingAdmin ( true ) ;
233+
234+ try {
235+ console . log ( "Making admin verification request for user:" , user . id ) ;
236+
237+ const response = await fetch ( '/api/admin/verify' , {
238+ method : 'POST' ,
239+ headers : {
240+ 'Content-Type' : 'application/json' ,
241+ } ,
242+ body : JSON . stringify ( { userId : user . id } )
243+ } ) ;
244+
245+ console . log ( "Admin verification response status:" , response . status ) ;
246+
247+ const responseData = await response . json ( ) ;
248+ console . log ( "Admin verification response:" , responseData ) ;
249+
250+ if ( response . ok && responseData . isAdmin ) {
251+ console . log ( "Admin access verified" ) ;
252+ setIsAdminVerified ( true ) ;
253+ setAdminToken ( responseData . adminToken ) ; // Store the admin token
254+ setError ( null ) ;
255+ // Start fetching requests with the token directly since state hasn't updated yet
256+ fetchRequests ( responseData . adminToken ) ;
257+ } else {
258+ console . log ( "Admin access denied:" , responseData . error ) ;
259+ setError ( responseData . error || 'Access denied. Admin privileges required.' ) ;
260+ setTimeout ( ( ) => router . push ( '/' ) , 3000 ) ;
261+ }
262+ } catch ( error ) {
263+ console . error ( 'Admin verification failed:' , error ) ;
264+ setError ( 'Failed to verify admin access. Please try again.' ) ;
265+ setTimeout ( ( ) => router . push ( '/' ) , 3000 ) ;
266+ } finally {
267+ setIsCheckingAdmin ( false ) ;
268+ }
269+ } ;
270+
271+ checkAdminAccess ( ) ;
272+ } , [ isAuthenticated , user , router , fetchRequests ] ) ;
273+
273274 const handleUpdateStatus = async ( status : 'accepted' | 'declined' ) => {
274275 if ( ! selectedRequest || ! user || ! isAdminVerified ) return ;
275276
@@ -761,7 +762,7 @@ const AdminProjectRequestsPage = () => {
761762 { selectedRequest . status !== 'pending' && (
762763 < div className = "flex gap-2" >
763764 < Button
764- onClick = { ( ) => handleUpdateStatus ( 'pending' as any ) }
765+ onClick = { ( ) => handleUpdateStatus ( 'pending' as 'accepted' | 'declined' ) }
765766 className = "bg-blue-500 hover:bg-blue-600 text-white"
766767 disabled = { isUpdating }
767768 >
0 commit comments