From 0e31e92c359db0df77d005422ea562057c573509 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 19 Jul 2023 14:00:45 -0400 Subject: [PATCH] small fix --- components/Modal/User/ChangePassword.tsx | 7 ++++--- components/Modal/User/PrivacySettings.tsx | 23 +++++++++++++++-------- components/Modal/User/ProfileSettings.tsx | 14 +++++++++++--- components/Modal/User/index.tsx | 2 -- pages/api/auth/[...nextauth].ts | 2 -- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/components/Modal/User/ChangePassword.tsx b/components/Modal/User/ChangePassword.tsx index 09e0f3b..5ccfe08 100644 --- a/components/Modal/User/ChangePassword.tsx +++ b/components/Modal/User/ChangePassword.tsx @@ -52,13 +52,13 @@ export default function ChangePassword({ toast.success("Settings Applied!"); if ( + user.email !== account.email || user.username !== account.username || - user.name !== account.name || - user.email !== account.email + user.name !== account.name ) { update({ username: user.username, - email: user.username, + email: user.email, name: user.name, }); @@ -71,6 +71,7 @@ export default function ChangePassword({ } else { toast.error("Passwords do not match."); } + setSubmitLoader(false); }; return ( diff --git a/components/Modal/User/PrivacySettings.tsx b/components/Modal/User/PrivacySettings.tsx index 8957d5f..79dbb5a 100644 --- a/components/Modal/User/PrivacySettings.tsx +++ b/components/Modal/User/PrivacySettings.tsx @@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useEffect, useState } from "react"; import Checkbox from "../../Checkbox"; import useAccountStore from "@/store/account"; import { AccountSettings } from "@/types/global"; -import { useSession } from "next-auth/react"; +import { signOut, useSession } from "next-auth/react"; import { faPenToSquare } from "@fortawesome/free-regular-svg-icons"; import SubmitButton from "../../SubmitButton"; import { toast } from "react-hot-toast"; @@ -59,18 +59,25 @@ export default function PrivacySettings({ if (response.ok) { toast.success("Settings Applied!"); - toggleSettingsModal(); - } else toast.error(response.data as string); - setSubmitLoader(false); + if ( + user.email !== account.email || + user.username !== account.username || + user.name !== account.name + ) { + update({ + username: user.username, + email: user.email, + name: user.name, + }); - if (user.username !== account.username || user.name !== account.name) - update({ username: user.username, name: user.name }); + signOut(); + } - if (response.ok) { setUser({ ...user, newPassword: undefined }); toggleSettingsModal(); - } + } else toast.error(response.data as string); + setSubmitLoader(false); }; return ( diff --git a/components/Modal/User/ProfileSettings.tsx b/components/Modal/User/ProfileSettings.tsx index 5090846..cee20bd 100644 --- a/components/Modal/User/ProfileSettings.tsx +++ b/components/Modal/User/ProfileSettings.tsx @@ -79,13 +79,13 @@ export default function ProfileSettings({ toast.success("Settings Applied!"); if ( + user.email !== account.email || user.username !== account.username || - user.name !== account.name || - user.email !== account.email + user.name !== account.name ) { update({ username: user.username, - email: user.username, + email: user.email, name: user.name, }); @@ -175,6 +175,14 @@ export default function ProfileSettings({ /> ) : undefined} + + {user.username !== account.username || + user.name !== account.name || + user.email !== account.email ? ( +

+ You will need to log back in after you apply the changes. +

+ ) : undefined} diff --git a/components/Modal/User/index.tsx b/components/Modal/User/index.tsx index eb9ee60..199d9bb 100644 --- a/components/Modal/User/index.tsx +++ b/components/Modal/User/index.tsx @@ -24,8 +24,6 @@ export default function UserModal({ }: Props) { const [user, setUser] = useState(activeUser); - console.log(activeUser); - return (
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 5da3fec..6de9f51 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -116,8 +116,6 @@ export const authOptions: AuthOptions = { PRICE_ID ); - subscription.isSubscriber; - if (subscription.subscriptionCanceledAt) { token.subscriptionCanceledAt = subscription.subscriptionCanceledAt; } else token.subscriptionCanceledAt = undefined;