From ecccf84c91e979d5817146a64a0bbd8009437ef9 Mon Sep 17 00:00:00 2001 From: ColinBuyck Date: Tue, 19 Dec 2023 19:39:41 -0800 Subject: [PATCH 1/2] fix: explicitly pass token --- .../core/src/auth/services/user.service.ts | 2 ++ shared-helpers/src/AuthContext.ts | 21 ++++++++++++------- .../src/components/users/FormUserConfirm.tsx | 12 +++++------ sites/partners/src/pages/reset-password.tsx | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/backend/core/src/auth/services/user.service.ts b/backend/core/src/auth/services/user.service.ts index b93d89e757..49cc2ff577 100644 --- a/backend/core/src/auth/services/user.service.ts +++ b/backend/core/src/auth/services/user.service.ts @@ -276,6 +276,8 @@ export class UserService { } if (user.confirmationToken !== token) { + console.log(user.confirmationToken) + console.log(token) throw new HttpException(USER_ERRORS.TOKEN_MISSING.message, USER_ERRORS.TOKEN_MISSING.status) } user.hitConfirmationURL = new Date() diff --git a/shared-helpers/src/AuthContext.ts b/shared-helpers/src/AuthContext.ts index 65c813518b..a18658bcae 100644 --- a/shared-helpers/src/AuthContext.ts +++ b/shared-helpers/src/AuthContext.ts @@ -296,7 +296,9 @@ export const AuthProvider: FunctionComponent = ({ child }, loginWithToken: async (token: string) => { dispatch(saveToken({ accessToken: token, apiUrl, dispatch })) - const profile = await userService?.userControllerProfile() + const profile = await userService?.userControllerProfile({ + headers: { Authorization: `Bearer ${token}` }, + }) if (profile) { dispatch(saveProfile(profile)) return profile @@ -317,12 +319,13 @@ export const AuthProvider: FunctionComponent = ({ child }) if (response) { dispatch(saveToken({ accessToken: response.accessToken, apiUrl, dispatch })) - // 12/18 - Short-term error fix to allow user accesss - // const profile = await userService?.userControllerProfile() - // if (profile) { - // dispatch(saveProfile(profile)) - // return profile - // } + const profile = await userService?.userControllerProfile({ + headers: { Authorization: `Bearer ${response.accessToken}` }, + }) + if (profile) { + dispatch(saveProfile(profile)) + return profile + } } return undefined } finally { @@ -335,7 +338,9 @@ export const AuthProvider: FunctionComponent = ({ child const response = await userService?.confirm({ body: { token } }) if (response) { dispatch(saveToken({ accessToken: response.accessToken, apiUrl, dispatch })) - const profile = await userService?.userControllerProfile() + const profile = await userService?.userControllerProfile({ + headers: { Authorization: `Bearer ${response.accessToken}` }, + }) if (profile) { dispatch(saveProfile(profile)) return profile diff --git a/sites/partners/src/components/users/FormUserConfirm.tsx b/sites/partners/src/components/users/FormUserConfirm.tsx index 6a9a57b432..f8b0020109 100644 --- a/sites/partners/src/components/users/FormUserConfirm.tsx +++ b/sites/partners/src/components/users/FormUserConfirm.tsx @@ -45,7 +45,7 @@ const FormUserConfirm = () => { password.current = watch("password", "") const [isLoginLoading, setLoginLoading] = useState(false) - const [isSubmitting, setSubmitting] = useState(false) + const [isTokenChecked, setIsTokenChecked] = useState(false) const [termsModal, setTermsModal] = useState(null) const [rerequestModalOpen, setRerequestModalOpen] = useState(false) const [newConfirmationRequested, setNewConfirmationRequested] = useState(false) @@ -58,10 +58,13 @@ const FormUserConfirm = () => { ] useEffect(() => { - if (!isSubmitting && token) { + console.log("In useEffect") + if (!isTokenChecked && token) { + console.log("checking token") userService .isUserConfirmationTokenValid({ body: { token } }) .then((res) => { + setIsTokenChecked(true) if (!res) { setRerequestModalOpen(true) } @@ -70,10 +73,9 @@ const FormUserConfirm = () => { setRerequestModalOpen(true) }) } - }, [isSubmitting, token, userService]) + }, [isTokenChecked, token, userService]) const onSubmit = async (data: FormUserConfirmFields) => { - setSubmitting(true) resetMutation() const body = { @@ -98,11 +100,9 @@ const FormUserConfirm = () => { setSiteAlertMessage(t(`users.accountConfirmed`), "success") void router.push("/") } else { - setSubmitting(false) setRerequestModalOpen(true) } } catch (err) { - setSubmitting(false) console.error(err) } } diff --git a/sites/partners/src/pages/reset-password.tsx b/sites/partners/src/pages/reset-password.tsx index 8f7c179fe2..40e470d057 100644 --- a/sites/partners/src/pages/reset-password.tsx +++ b/sites/partners/src/pages/reset-password.tsx @@ -33,7 +33,7 @@ const ResetPassword = () => { try { await resetPassword(token.toString(), password, passwordConfirmation) setSiteAlertMessage(t(`account.settings.passwordSuccess`), "notice") - await router.push("/sign-in") + await router.push("/") window.scrollTo(0, 0) } catch (err) { const { status, data } = err.response || {} From 354f1f4d14863ab4859a5f8bf1d59bcbb2a30e6c Mon Sep 17 00:00:00 2001 From: ColinBuyck Date: Tue, 19 Dec 2023 19:43:53 -0800 Subject: [PATCH 2/2] fix: replace temp error messaging --- backend/core/src/auth/services/user.service.ts | 2 -- sites/partners/src/components/users/FormUserConfirm.tsx | 2 -- sites/partners/src/pages/reset-password.tsx | 4 ++-- sites/public/src/pages/reset-password.tsx | 6 +++--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/core/src/auth/services/user.service.ts b/backend/core/src/auth/services/user.service.ts index 49cc2ff577..b93d89e757 100644 --- a/backend/core/src/auth/services/user.service.ts +++ b/backend/core/src/auth/services/user.service.ts @@ -276,8 +276,6 @@ export class UserService { } if (user.confirmationToken !== token) { - console.log(user.confirmationToken) - console.log(token) throw new HttpException(USER_ERRORS.TOKEN_MISSING.message, USER_ERRORS.TOKEN_MISSING.status) } user.hitConfirmationURL = new Date() diff --git a/sites/partners/src/components/users/FormUserConfirm.tsx b/sites/partners/src/components/users/FormUserConfirm.tsx index f8b0020109..40c3330b84 100644 --- a/sites/partners/src/components/users/FormUserConfirm.tsx +++ b/sites/partners/src/components/users/FormUserConfirm.tsx @@ -58,9 +58,7 @@ const FormUserConfirm = () => { ] useEffect(() => { - console.log("In useEffect") if (!isTokenChecked && token) { - console.log("checking token") userService .isUserConfirmationTokenValid({ body: { token } }) .then((res) => { diff --git a/sites/partners/src/pages/reset-password.tsx b/sites/partners/src/pages/reset-password.tsx index 40e470d057..9b53dc4a1a 100644 --- a/sites/partners/src/pages/reset-password.tsx +++ b/sites/partners/src/pages/reset-password.tsx @@ -31,8 +31,8 @@ const ResetPassword = () => { const { password, passwordConfirmation } = data try { - await resetPassword(token.toString(), password, passwordConfirmation) - setSiteAlertMessage(t(`account.settings.passwordSuccess`), "notice") + const user = await resetPassword(token.toString(), password, passwordConfirmation) + setSiteAlertMessage(t(`authentication.signIn.success`, { name: user.firstName }), "success") await router.push("/") window.scrollTo(0, 0) } catch (err) { diff --git a/sites/public/src/pages/reset-password.tsx b/sites/public/src/pages/reset-password.tsx index 41ac340aa9..f2892e8de7 100644 --- a/sites/public/src/pages/reset-password.tsx +++ b/sites/public/src/pages/reset-password.tsx @@ -40,9 +40,9 @@ const ResetPassword = () => { const { password, passwordConfirmation } = data try { - await resetPassword(token.toString(), password, passwordConfirmation) - setSiteAlertMessage(t(`account.settings.passwordSuccess`), "notice") - await router.push("/sign-in") + const user = await resetPassword(token.toString(), password, passwordConfirmation) + setSiteAlertMessage(t(`authentication.signIn.success`, { name: user.firstName }), "success") + await router.push("/account/dashboard") } catch (err) { const { status, data } = err.response || {} if (status === 400) {