Skip to content

Commit

Permalink
update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Dec 19, 2024
1 parent 24a3a33 commit 54ef236
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
8 changes: 5 additions & 3 deletions backend/onyx/auth/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,12 @@ async def on_after_forgot_password(
) -> None:
if not EMAIL_CONFIGURED:
logger.error(
"User forgot their password but email is not configured.",
extra={"user_email": user.email},
"Email is not configured. Please configure email in the admin panel"
)
raise HTTPException(
status.HTTP_500_INTERNAL_SERVER_ERROR,
"Your admin has not enbaled this feature.",
)
return
send_forgot_password_email(user.email, token)

async def on_after_request_verify(
Expand Down
4 changes: 1 addition & 3 deletions backend/onyx/configs/app_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@
SMTP_PORT = int(os.environ.get("SMTP_PORT") or "587")
SMTP_USER = os.environ.get("SMTP_USER", "your-email@gmail.com")
SMTP_PASS = os.environ.get("SMTP_PASS", "your-gmail-password")
EMAIL_CONFIGURED = (
SMTP_SERVER is not None and SMTP_USER is not None and SMTP_PASS is not None
)
EMAIL_CONFIGURED = bool(SMTP_SERVER) and bool(SMTP_USER) and bool(SMTP_PASS)
EMAIL_FROM = os.environ.get("EMAIL_FROM") or SMTP_USER

# If set, Onyx will listen to the `expires_at` returned by the identity
Expand Down
7 changes: 6 additions & 1 deletion web/src/app/auth/forgot-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ForgotPasswordPage: React.FC = () => {
<AuthFlowContainer>
<div className="flex flex-col w-full justify-center">
<CardSection className="mt-4 w-full">
{" "}
<div className="flex">
<Title className="mb-2 mx-auto font-bold">Forgot Password</Title>
</div>
Expand All @@ -49,9 +50,13 @@ const ForgotPasswordPage: React.FC = () => {
"Password reset email sent. Please check your inbox.",
});
} catch (error) {
const errorMessage =
error instanceof Error
? error.message
: "An error occurred. Please try again.";
setPopup({
type: "error",
message: "An error occurred. Please try again.",
message: errorMessage,
});
} finally {
setIsWorking(false);
Expand Down
5 changes: 4 additions & 1 deletion web/src/app/auth/forgot-password/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export const forgotPassword = async (email: string): Promise<void> => {
});

if (!response.ok) {
throw new Error("Failed to send password reset email");
const error = await response.json();
const errorMessage =
error?.detail || "An error occurred during password reset.";
throw new Error(errorMessage);
}
};

Expand Down
24 changes: 16 additions & 8 deletions web/src/app/auth/login/EmailPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { requestEmailVerification } from "../lib";
import { useState } from "react";
import { Spinner } from "@/components/Spinner";
import { set } from "lodash";
import { NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED } from "@/lib/constants";
import Link from "next/link";

export function EmailPasswordForm({
isSignup = false,
Expand Down Expand Up @@ -110,15 +112,21 @@ export function EmailPasswordForm({
placeholder="**************"
/>

<div className="flex">
<Button
type="submit"
disabled={isSubmitting}
className="mx-auto w-full"
{NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && !isSignup && (
<Link
href="/auth/forgot-password"
className="text-sm text-link font-medium whitespace-nowrap"
>
{isSignup ? "Sign Up" : "Log In"}
</Button>
</div>
Forgot Password?
</Link>
)}
<Button
type="submit"
disabled={isSubmitting}
className="mx-auto w-full"
>
{isSignup ? "Sign Up" : "Log In"}
</Button>
</Form>
)}
</Formik>
Expand Down
13 changes: 1 addition & 12 deletions web/src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const Page = async (props: {
</Title>
</div>
<EmailPasswordForm nextUrl={nextUrl} />
<div className="flex flex-col gap-y-2 items-start">
<div className="flex flex-col gap-y-2 items-center">
<Text className="mt-4 ">
Don&apos;t have an account?{" "}
<Link
Expand All @@ -144,17 +144,6 @@ const Page = async (props: {
Create an account
</Link>
</Text>
{NEXT_PUBLIC_FORGOT_PASSWORD_ENABLED && (
<Text>
Forgot password?{" "}
<Link
href="/auth/forgot-password"
className="text-link font-medium"
>
Reset Password
</Link>
</Text>
)}
</div>
</CardSection>
)}
Expand Down
5 changes: 4 additions & 1 deletion web/src/app/auth/reset-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ const ResetPasswordPage: React.FC = () => {
setPopup({
type: "success",
message:
"Password reset successfully. You can now log in with your new password.",
"Password reset successfully. Redirecting to login...",
});
setTimeout(() => {
redirect("/auth/login");
}, 1000);
} catch (error) {
setPopup({
type: "error",
Expand Down

0 comments on commit 54ef236

Please sign in to comment.