MENG21 commited on
Commit
ef1081e
·
1 Parent(s): ec6b621
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -179,7 +179,8 @@ def main():
179
  st.error('Student ID not found. Please try again.')
180
 
181
  if st.button("Logout"):
182
- del st.session_state['credentials']
 
183
  st.rerun()
184
 
185
  # Function to handle OAuth callback
@@ -189,16 +190,23 @@ def handle_callback():
189
  flow.fetch_token(code=st.query_params["code"])
190
  credentials = flow.credentials
191
  st.session_state['credentials'] = credentials.to_json()
 
192
  logging.debug("Token fetch successful")
193
  st.success("Authentication successful!")
194
- return credentials
 
195
  except Exception as e:
196
  logging.error(f"Error during authentication: {str(e)}")
197
  st.error(f"Authentication failed: {str(e)}")
 
 
 
198
 
199
  if __name__ == '__main__':
200
  logging.debug("Starting the application")
201
  if 'code' in st.query_params:
202
  logging.debug("Authorization code found in query parameters")
203
  handle_callback()
 
 
204
  main()
 
179
  st.error('Student ID not found. Please try again.')
180
 
181
  if st.button("Logout"):
182
+ for key in list(st.session_state.keys()):
183
+ del st.session_state[key]
184
  st.rerun()
185
 
186
  # Function to handle OAuth callback
 
190
  flow.fetch_token(code=st.query_params["code"])
191
  credentials = flow.credentials
192
  st.session_state['credentials'] = credentials.to_json()
193
+ st.session_state['authenticated'] = True
194
  logging.debug("Token fetch successful")
195
  st.success("Authentication successful!")
196
+ time.sleep(2) # Give user time to see the success message
197
+ st.rerun() # Rerun the app to clear the URL parameters
198
  except Exception as e:
199
  logging.error(f"Error during authentication: {str(e)}")
200
  st.error(f"Authentication failed: {str(e)}")
201
+ st.session_state['authenticated'] = False
202
+ if 'credentials' in st.session_state:
203
+ del st.session_state['credentials']
204
 
205
  if __name__ == '__main__':
206
  logging.debug("Starting the application")
207
  if 'code' in st.query_params:
208
  logging.debug("Authorization code found in query parameters")
209
  handle_callback()
210
+ elif st.session_state.get('authenticated', False):
211
+ st.success("You are already authenticated.")
212
  main()