diff --git a/src/interface/web/app/components/loginPrompt/loginPrompt.tsx b/src/interface/web/app/components/loginPrompt/loginPrompt.tsx index 70b62b33..0aa150ea 100644 --- a/src/interface/web/app/components/loginPrompt/loginPrompt.tsx +++ b/src/interface/web/app/components/loginPrompt/loginPrompt.tsx @@ -232,7 +232,7 @@ function EmailSignInContext({ const [otpError, setOTPError] = useState(""); function checkOTPAndRedirect() { - const verifyUrl = `/auth/magic?code=${otp}`; + const verifyUrl = `/auth/magic?code=${otp}&email=${email}`; fetch(verifyUrl, { method: "GET", diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index 1a99d04c..140680a4 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -269,8 +269,8 @@ async def astart_trial_subscription(user: KhojUser) -> Subscription: return subscription -async def aget_user_validated_by_email_verification_code(code: str) -> KhojUser: - user = await KhojUser.objects.filter(email_verification_code=code).afirst() +async def aget_user_validated_by_email_verification_code(code: str, email: str) -> KhojUser: + user = await KhojUser.objects.filter(email_verification_code=code, email=email).afirst() if not user: return None diff --git a/src/khoj/routers/auth.py b/src/khoj/routers/auth.py index 0e401744..a01bf6fb 100644 --- a/src/khoj/routers/auth.py +++ b/src/khoj/routers/auth.py @@ -99,8 +99,8 @@ async def login_magic_link(request: Request, form: MagicLinkForm): @auth_router.get("/magic") -async def sign_in_with_magic_link(request: Request, code: str): - user = await aget_user_validated_by_email_verification_code(code) +async def sign_in_with_magic_link(request: Request, code: str, email: str): + user = await aget_user_validated_by_email_verification_code(code, email) if user: id_info = { "email": user.email, diff --git a/src/khoj/routers/email.py b/src/khoj/routers/email.py index 27dd8f5d..79061da0 100644 --- a/src/khoj/routers/email.py +++ b/src/khoj/routers/email.py @@ -33,7 +33,7 @@ def is_resend_enabled(): async def send_magic_link_email(email, unique_id, host): - sign_in_link = f"{host}auth/magic?code={unique_id}" + sign_in_link = f"{host}auth/magic?code={unique_id}&email={email}" if not is_resend_enabled(): logger.debug(f"Email sending disabled. Share this sign-in link with the user: {sign_in_link}")