Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1640/resolve reset confirmation #1650

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions shared-helpers/src/AuthContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ export const AuthProvider: FunctionComponent<React.PropsWithChildren> = ({ 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
Expand All @@ -317,12 +319,13 @@ export const AuthProvider: FunctionComponent<React.PropsWithChildren> = ({ 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 {
Expand All @@ -335,7 +338,9 @@ export const AuthProvider: FunctionComponent<React.PropsWithChildren> = ({ 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
Expand Down
10 changes: 4 additions & 6 deletions sites/partners/src/components/users/FormUserConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -58,10 +58,11 @@ const FormUserConfirm = () => {
]

useEffect(() => {
if (!isSubmitting && token) {
if (!isTokenChecked && token) {
userService
.isUserConfirmationTokenValid({ body: { token } })
.then((res) => {
setIsTokenChecked(true)
if (!res) {
setRerequestModalOpen(true)
}
Expand All @@ -70,10 +71,9 @@ const FormUserConfirm = () => {
setRerequestModalOpen(true)
})
}
}, [isSubmitting, token, userService])
}, [isTokenChecked, token, userService])

const onSubmit = async (data: FormUserConfirmFields) => {
setSubmitting(true)
resetMutation()

const body = {
Expand All @@ -98,11 +98,9 @@ const FormUserConfirm = () => {
setSiteAlertMessage(t(`users.accountConfirmed`), "success")
void router.push("/")
} else {
setSubmitting(false)
setRerequestModalOpen(true)
}
} catch (err) {
setSubmitting(false)
console.error(err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions sites/partners/src/pages/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,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("/")
window.scrollTo(0, 0)
} catch (err) {
const { status, data } = err.response || {}
Expand Down
6 changes: 3 additions & 3 deletions sites/public/src/pages/reset-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down