@@ -45,12 +45,20 @@ export default function FoodDistributionPage() {
4545 const teamCode = params . teamCode as string ;
4646
4747 // --- State Hooks ---
48+ const [ token , setToken ] = useState < string > ( "" ) ;
49+ const [ inputToken , setInputToken ] = useState < string > ( "" ) ;
4850 const [ membersData , setMembersData ] = useState < MemberList > ( [ ] ) ;
4951 const [ teamName , setTeamName ] = useState ( '' ) ;
5052 const [ loading , setLoading ] = useState ( true ) ;
5153 const [ error , setError ] = useState < string | null > ( null ) ;
5254
5355 // --- Data Fetching Effect ---
56+ useEffect ( ( ) => {
57+ // load token from localStorage
58+ const stored = typeof window !== 'undefined' ? localStorage . getItem ( 'admin_token' ) : null ;
59+ if ( stored ) setToken ( stored ) ;
60+ } , [ ] ) ;
61+
5462 useEffect ( ( ) => {
5563 if ( ! teamCode || teamCode === "undefined" ) {
5664 setLoading ( false ) ;
@@ -62,7 +70,9 @@ export default function FoodDistributionPage() {
6270 setLoading ( true ) ;
6371 setError ( null ) ;
6472 try {
65- const response = await fetch ( `/api/admin/food/${ teamCode } ` ) ;
73+ const response = await fetch ( `/api/admin/food/${ teamCode } ` , {
74+ headers : token ? { Authorization : `Bearer ${ token } ` } : { } ,
75+ } ) ;
6676 if ( ! response . ok ) {
6777 const err = await response . json ( ) ;
6878 throw new Error ( err . message || 'Team not found' ) ;
@@ -85,8 +95,10 @@ export default function FoodDistributionPage() {
8595 }
8696 } ;
8797
88- fetchTeam ( ) ;
89- } , [ teamCode ] ) ;
98+ if ( token ) {
99+ fetchTeam ( ) ;
100+ }
101+ } , [ teamCode , token ] ) ;
90102
91103 // --- Update Handler ---
92104 const handleFoodToggle = async (
@@ -107,7 +119,7 @@ export default function FoodDistributionPage() {
107119 try {
108120 const response = await fetch ( '/api/admin/food/update' , {
109121 method : 'POST' ,
110- headers : { 'Content-Type' : 'application/json' } ,
122+ headers : { 'Content-Type' : 'application/json' , ... ( token ? { Authorization : `Bearer ${ token } ` } : { } ) } ,
111123 body : JSON . stringify ( {
112124 docId : docId ,
113125 field : field ,
@@ -136,6 +148,60 @@ export default function FoodDistributionPage() {
136148 if ( loading ) { /* ... */ }
137149 if ( error ) { /* ... */ }
138150
151+ if ( ! token ) {
152+ return (
153+ < div style = { { maxWidth : 420 , margin : '64px auto' , padding : 24 } } >
154+ < Toaster />
155+ < h2 style = { { fontSize : 24 , fontWeight : 700 , marginBottom : 12 } } > Admin Login</ h2 >
156+ < p style = { { color : '#666' , marginBottom : 16 } } > Enter the admin access token.</ p >
157+ < form
158+ onSubmit = { ( e ) => {
159+ e . preventDefault ( ) ;
160+ const trimmed = inputToken . trim ( ) ;
161+ if ( ! trimmed ) return ;
162+ localStorage . setItem ( 'admin_token' , trimmed ) ;
163+ setToken ( trimmed ) ;
164+ } }
165+ style = { { display : 'flex' , gap : 8 } }
166+ >
167+ < input
168+ type = "password"
169+ placeholder = "Admin token"
170+ value = { inputToken }
171+ onChange = { ( e ) => setInputToken ( e . target . value ) }
172+ style = { { flex : 1 , padding : '10px 12px' , border : '1px solid #ddd' , borderRadius : 8 } }
173+ />
174+ < button
175+ type = "submit"
176+ style = { {
177+ padding : '12px 32px' ,
178+ borderRadius : 12 ,
179+ background : 'linear-gradient(135deg, #FF0500 0%, #c53030 100%)' ,
180+ color : 'white' ,
181+ border : 'none' ,
182+ fontWeight : 'bold' ,
183+ textTransform : 'uppercase' ,
184+ letterSpacing : '1px' ,
185+ cursor : 'pointer' ,
186+ transition : 'all 0.3s ease' ,
187+ boxShadow : '0 4px 15px rgba(255, 5, 0, 0.4)'
188+ } }
189+ onMouseOver = { ( e ) => {
190+ e . currentTarget . style . transform = 'translateY(-2px)' ;
191+ e . currentTarget . style . boxShadow = '0 6px 20px rgba(255, 5, 0, 0.6)' ;
192+ } }
193+ onMouseOut = { ( e ) => {
194+ e . currentTarget . style . transform = 'translateY(0)' ;
195+ e . currentTarget . style . boxShadow = '0 4px 15px rgba(255, 5, 0, 0.4)' ;
196+ } }
197+ >
198+ Continue
199+ </ button >
200+ </ form >
201+ </ div >
202+ ) ;
203+ }
204+
139205 return (
140206 < div className = { styles . pageContainer } >
141207 < Toaster />
0 commit comments