-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/ magic link auth #22
Open
ghostleek
wants to merge
117
commits into
main
Choose a base branch
from
feat-magic-link-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Assistant generated file changes: - app/chat/chat_handler.py: Create new chat handler module - main.py: Refactor main.py to use chat handler - app/chat/__init__.py: Create chat module init --- User prompt: actually refactor more aggressively by separating concerns and isolate it from main.py into another file
Assistant generated file changes: - app/chat/chat_handler.py: Integrate improved chat UI --- User prompt: okay nevermind. lets ignore that. integrate this https://github.com/pierrelouisbescond/streamlit-chat-ui-improvement
Assistant generated file changes: - .streamlit/config.toml: Add Streamlit config to disable email prompt --- User prompt: Can you help me with this deployment issue?
Assistant generated file changes: - app/chat/chat_handler.py: Remove secrets.toml dependency - main.py: Update OpenAI client initialization - sidebar.py: Update admin password check - app/db/database_connection.py: Update database connection --- User prompt: I've added the secrets directly in replit secrets handler instead of secrets.toml. can you amend my code accordingly?
…components Assistant generated file changes: - app/chat/chat_handler.py: Replace custom chat UI with built-in Streamlit components --- User prompt: ModuleNotFoundError: No module named 'streamlit_chat_ui_improvement' Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 5, in <module> from app.chat.chat_handler import initialize_chat_state, display_chat_history, handle_chat_interaction File "/home/runner/workspace/app/chat/chat_handler.py", line 15, in <module> from streamlit_chat_ui_improvement import chat_ui
Assistant generated file changes: - sidebar.py: Add os import --- User prompt: leNameError: name 'os' is not defined Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 35, in <module> main() File "/home/runner/workspace/main.py", line 20, in main setup_sidebar() File "/home/runner/workspace/sidebar.py", line 21, in setup_sidebar if admin_password == os.environ["ADMIN_PASSWORD"]: ^^
Assistant generated file changes: - sidebar.py: Add environment variable check --- User prompt: KeyError: 'ADMIN_PASSWORD' Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 35, in <module> main() File "/home/runner/workspace/main.py", line 20, in main setup_sidebar() File "/home/runner/workspace/sidebar.py", line 22, in setup_sidebar if admin_password == os.environ["ADMIN_PASSWORD"]: ~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "<frozen os>", line 714, in __getitem__
Assistant generated file changes: - main.py: Clean up imports and add docstring - app/chat/chat_handler.py: Improve chat handler organization - sidebar.py: Reorganize sidebar code --- User prompt: Please clean up the the code to be more readable.
Assistant generated file changes: - app/db/database_connection.py: Add better fallback values, Update fallback description --- User prompt: Default app title here. Default app description here. KeyError: 'OPENAI_API_KEY' Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 48, in <module> main() File "/home/runner/workspace/main.py", line 40, in main client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "<frozen os>", line 714, in __getitem__
…estriction Assistant generated file changes: - app/auth/auth_handler.py: Add magic link authentication - main.py: Add authentication check --- User prompt: okay this works now. can we add a magic link email auth with sendgrid as the transactional email service? gate the users to @moe.edu.sg @moe.gov.sg @schools.gov.sg
…pdate streamlit-feedback.
Assistant generated file changes: - main.py: Update query params usage --- User prompt: Please replace st.experimental_get_query_params with st.query_params. st.experimental_get_query_params will be removed after 2024-04-11. Refer to our docs page for more information.
Assistant generated file changes: - app/auth/auth_handler.py: Add better error logging for SendGrid --- User prompt: emails doesn't seem to be sent even though there is a toast that says "login sent"
Assistant generated file changes: - app/auth/auth_handler.py: Add detailed email debugging --- User prompt: I don't have it in my spam folder. why else might email not be sent?
Assistant generated file changes: - app/auth/auth_handler.py: Add SendGrid detailed error logging --- User prompt: in sendgrid, it shows 3 requests but 0% delivered. why might that be the case?
Assistant generated file changes: - app/auth/auth_handler.py: Improve SendGrid error handling --- User prompt: Sending to: [email protected] From email: [email protected] Magic link: https://chergpt.replit.app//verify?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImxlZV9rYWhfaG93QG1vZS5lZHUuc2ciLCJleHAiOjE3Mzc5ODg5ODR9.06Cz-HY3gr_qIwDeWcw6Fn-hZUYpOeOLBKwdoGvO0lY SendGrid Details: From Email: [email protected] To Email: [email protected] Status Code: 202 Response Headers: Server: nginx Date: Mon, 27 Jan 2025 14:28:04 GMT Content-Length: 0 Connection: close X-Message-Id: 1uRPRKbmQq279UR9TVFF7Q Access-Control-Allow-Origin: https://sendgrid.api-docs.io Access-Control-Allow-Methods: POST Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl Access-Control-Max-Age: 600 X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Security-Policy: frame-ancestors 'none' Cache-Control: no-cache X-Content-Type-Options: no-sniff Referrer-Policy: strict-origin-when-cross-origin Response Body: No body Error checking verified senders: HTTP Error 403: Forbidden Login link sent! Please check your email. why forbidden?
Assistant generated file changes: - app/auth/auth_handler.py: Add clearer SendGrid status messages --- User prompt: Login Enter your MOE email [email protected] Sending to: [email protected] From email: [email protected] Magic link: https://chergpt.replit.app//verify?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImxlZV9rYWhfaG93QG1vZS5lZHUuc2ciLCJleHAiOjE3Mzc5OTAyNDV9._oKjmk_YYg3I6kclUabfZfMnJ53IH3o8FnpIuV-y714 SendGrid Details: From Email: [email protected] To Email: [email protected] Status Code: 202 Response Headers: Server: nginx Date: Mon, 27 Jan 2025 14:49:06 GMT Content-Length: 0 Connection: close X-Message-Id: gw5Gmf3hTzeGdxZLoAq_RA Access-Control-Allow-Origin: https://sendgrid.api-docs.io Access-Control-Allow-Methods: POST Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl Access-Control-Max-Age: 600 X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Security-Policy: frame-ancestors 'none' Cache-Control: no-cache X-Content-Type-Options: no-sniff Referrer-Policy: strict-origin-when-cross-origin Response Body: No body Email sending attempt completed.
Assistant generated file changes: - app/auth/auth_handler.py: Add Resend as email provider, Update send_magic_link to use Resend --- User prompt: is there another service like sendgrid I can try?
Assistant generated file changes: - app/auth/auth_handler.py: Make email sending more robust with fallback, Add error handling for missing resend --- User prompt: ModuleNotFoundError: No module named 'resend' Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 23, in <module> from app.auth.auth_handler import is_valid_email_domain, generate_magic_link, send_magic_link, verify_token File "/home/runner/workspace/app/auth/auth_handler.py", line 3, in <module> import resend
Assistant generated file changes: - app/auth/auth_handler.py: Update logging messages for Resend --- User prompt: I think the code still checks for sendgrid instead of resend: Sending to: [email protected] From email: [email protected] Magic link: https://chergpt.replit.app//verify?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImxlZV9rYWhfaG93QG1vZS5lZHUuc2ciLCJleHAiOjE3Mzc5OTExNDJ9.QXI2KtJ-XWZsCcnq8LP7QnY7N4DcR2aQEqn3tKtC5CM SendGrid Error: You can only send testing emails to your own email address ([email protected]). To send emails to other recipients, please verify a domain at resend.com/domains, and change the from address to an email using this domain. Failed to send login link.
Assistant generated file changes: - app/auth/auth_handler.py: Add clearer from email logging --- User prompt: is the email sending from [email protected]?
Assistant generated file changes: - app/auth/auth_handler.py: Update default from email --- User prompt: let's change the resend_from_email to [email protected]
Assistant generated file changes: - app/auth/auth_handler.py: Remove debug logging for email details --- User prompt: remove the error logging sections like: Email Details: To: [email protected] From: [email protected] (Using Resend) Magic link: https://chergpt.replit.app//verify?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImxlZV9rYWhfaG93QG1vZS5lZHUuc2ciLCJleHAiOjE3Mzc5OTI1Mjh9.T3OzJOFndU_YYpx7SRMjcHS0p25cHSvGS0aEhmEcPGo Resend Details: From Email: [email protected] To Email: [email protected] Email sending attempt completed.
Assistant generated file changes: - main.py: Update login screen layout --- User prompt: for the login screen, 1 change title to: Login 2 create a 2-column layout that stacks on moble 1st column: login 2nd column: CherGPT description: chat assistant for teaching and learning
…ication and improved UI.
Assistant generated file changes: - app/db/database_connection.py: Add new tables for user prompts and sessions, Add functions to manage user prompts and sessions --- User prompt: for every authenticated user, they should be able to load their own custom prompts and share a particular url for that unique session with the custom prompt loaded Help me relook the db schema for this to happen
Assistant generated file changes: - main.py: Update login section with UI card --- User prompt: for the login section/ input, let's use with ui.card(key="card1") : ui element ("span", children=["Email"], className="text-gray-400 text-sm font-m ui element("input", key="email_input", placeholder="Login with @moe, @school or @string email") ui element ("button", text="Send magic link", key="button", className="m-1")
Assistant generated file changes: - main.py: Fix syntax error in button element --- User prompt: Script execution error File "/home/runner/workspace/main.py", line 97 if ui.element("button", text="Send Magic Link")): ^ SyntaxError: unmatched ')' Help fix my errors
Assistant generated file changes: - main.py: Fix email variable reference --- User prompt: UnboundLocalError: cannot access local variable 'email' where it is not associated with a value Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 134, in <module> main() File "/home/runner/workspace/main.py", line 94, in main st.session_state.authenticated_email = email ^^^^^
Replit-Restored-To:524fb312a36e6f698246ca667c1127e792f105a4
…ove error handling.
Assistant generated file changes: - main.py: Nest dev login inside ui card --- User prompt: reference this code snipplet for synax with ui.card(key="card1"): with ui.card(key="card2"): ui.element("input", key="card2_input") ui.element("button", key="card2_btn", text="Nest Submmit", variant="outline") ui.element("button", key="card1_btn", text="Hello World") Let's nest the dev login component inside the card
Replit-Restored-To:e9a51de10897788a0208535ace2a57c4af53bdae
Assistant generated file changes: - main.py: Fix email variable access --- User prompt: UnboundLocalError: cannot access local variable 'email' where it is not associated with a value Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 133, in <module> main() File "/home/runner/workspace/main.py", line 92, in main st.session_state.authenticated_email = email ^^^^^
…nly sent if email is valid.
Assistant generated file changes: - main.py: Fix dev login button functionality --- User prompt: when i click on "dev login" nothing happens
Assistant generated file changes: - app/db/database_connection.py: Add missing os import --- User prompt: ERROR:root:Failed to connect to the database: name 'os' is not defined ERROR:root:Failed to connect to the database for fetching logs.
…gin functionality.
Assistant generated file changes: - app/db/database_connection.py: Add conversation_id column to chat_logs - app/chatlog/chatlog_handler.py: Remove duplicate table creation --- User prompt: ERROR:root:Error fetching and batching chat logs: column "conversation_id" does not exist LINE 1: SELECT conversation_id, prompt, response FROM chat_logs
…ent and simplify magic link sending.
Assistant generated file changes: - main.py: Update dev login button styling and placement --- User prompt: the button dev login should be full width and below the card. it should replace send magic link in development/ testing
Assistant generated file changes: - main.py: Fix email input handling for dev login --- User prompt: even when an email address is given, clicking on dev login results in an error: Please enter an email address
Assistant generated file changes: - main.py: Fix dev login functionality --- User prompt: still encountering the same error. having an email in the card and clicking on "dev login" does not work
Assistant generated file changes: - main.py: Fix dev login email handling --- User prompt: still encountering an error when I click "dev login" with a valid email input "[email protected]". please debug
Assistant generated file changes: - main.py: Fix email input value access --- User prompt: AttributeError: 'UIElement' object has no attribute 'get' Traceback: File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec exec(code, module.__dict__) File "/home/runner/workspace/main.py", line 137, in <module> main() File "/home/runner/workspace/main.py", line 92, in main email = email_input.get('value', '') ^^^^^^^^^^^^^^^ File "/home/runner/workspace/.pythonlibs/lib/python3.12/site-packages/streamlit_shadcn_ui/py_components/base/element.py", line 74, in __getattr__ raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{item}'")
…he dev login and magic link functionality.
…onents Assistant generated file changes: - main.py: Replace shadcn login with Streamlit components --- User prompt: still getting the error. maybe we try removing shadcn for the login component?
Assistant generated file changes: - main.py: Fix dev mode login flow --- User prompt: in development, clicking on dev login should go straight to the interface instead of showing magic link
Assistant generated file changes: - main.py: Fix indentation in login logic --- User prompt: File "/home/runner/workspace/main.py", line 99 if email and is_valid_email_domain(email): ^ IndentationError: expected an indented block after 'if' statement on line 95
Assistant generated file changes: - sidebar.py: Add immediate reloading after updates --- User prompt: the updates only show after clicking twice to reload the session. is it possible to show the changes after clicking update title, description and custom instructions immediately?
Assistant generated file changes: - main.py: Fix syntax error by removing extra 'x' character --- User prompt: fix "script execution error" File "/home/runner/workspace/main.py", line 89 st.session_state.authenticated_email = email.strip()x ^ SyntaxError: invalid syntax Replit-Commit-Author: Assistant Replit-Commit-Session-Id: eef09fe0-96c9-46ff-8f08-3b7ef7fe8e1f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.