Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fix occasional crash when accessing settings (#1982)

Luke Vellafc958bef83d2
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx
index 03c901379..0f58bfd1f 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/profile-email-address.tsx
@@ -35,7 +35,7 @@ export const ProfileEmailAddress = () => {
const posthog = usePostHog();
const form = useForm<EmailChangeFormData>({
defaultValues: {
- email: user.email,
+ email: user?.email,
},
resolver: zodResolver(emailChangeFormData),
});
@@ -84,6 +84,11 @@ export const ProfileEmailAddress = () => {
}, [posthog, t]);
const { handleSubmit, formState, reset } = form;
+
+ if (!user) {
+ return <div>You need to be logged in to see this page.</div>;
+ }
+
return (
<div className="grid gap-y-4">
<Form {...form}>
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/profile-picture.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/profile-picture.tsx
index 324bd583e..a0ef6c063 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/profile-picture.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/profile-picture.tsx
@@ -32,7 +32,7 @@ function ProfilePictureUpload() {
posthog?.capture("remove profile picture");
};
- if (!user) return null;
+ if (!user) return <div>You need to be logged in to see this page.</div>;
return (
<ImageUpload>
diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx
index 93094554d..a385af6ca 100644
--- a/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx
@@ -3,6 +3,7 @@ import { Alert, AlertDescription } from "@rallly/ui/alert";
import { Button } from "@rallly/ui/button";
import { toast } from "@rallly/ui/sonner";
import { MailWarningIcon } from "lucide-react";
+import { useRouter } from "next/navigation";
import React from "react";
import { Trans } from "@/components/trans";
import { useAuthenticatedUser } from "@/components/user-provider";
@@ -10,12 +11,20 @@ import { authClient } from "@/lib/auth-client";
export function SetupPasswordForm() {
const { user } = useAuthenticatedUser();
+ const router = useRouter();
const [isLoading, setIsLoading] = React.useState(false);
const [isSuccess, setIsSuccess] = React.useState(false);
const onSubmit = async () => {
setIsLoading(true);
+ if (!user?.email) {
+ router.push(
+ `/login?redirectTo=${encodeURIComponent("/settings/security")}`,
+ );
+ return;
+ }
+
// For users without passwords, we need to use the password reset flow
// First request a password reset
const resetRes = await authClient.requestPasswordReset({
diff --git a/apps/web/src/components/user-dropdown.tsx b/apps/web/src/components/user-dropdown.tsx
index f8012fd2f..00359b324 100644
--- a/apps/web/src/components/user-dropdown.tsx
+++ b/apps/web/src/components/user-dropdown.tsx
@@ -30,6 +30,7 @@ import { useAuthenticatedUser } from "./user-provider";
export const UserDropdown = ({ className }: { className?: string }) => {
const { user } = useAuthenticatedUser();
+ if (!user) return null;
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger
diff --git a/apps/web/src/components/user-provider.tsx b/apps/web/src/components/user-provider.tsx
index b9ac66592..8b5b075a8 100644
--- a/apps/web/src/components/user-provider.tsx
+++ b/apps/web/src/components/user-provider.tsx
@@ -32,7 +32,7 @@ export const useUser = () => {
export const useAuthenticatedUser = () => {
const { user } = useUser();
if (!user || user.isGuest) {
- throw new Error("User is not defined");
+ return { user: null };
}
return { user };