MENG21 commited on
Commit
4dcf425
·
1 Parent(s): ef1081e
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -179,8 +179,7 @@ def 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,23 +189,17 @@ def handle_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()
 
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
  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
+ pass
197
+ # logging.error(f"Error during authentication: {str(e)}")
198
+ # st.error(f"Authentication failed: {str(e)}")
 
 
199
 
200
  if __name__ == '__main__':
201
  logging.debug("Starting the application")
202
  if 'code' in st.query_params:
203
  logging.debug("Authorization code found in query parameters")
204
  handle_callback()
 
 
205
  main()