Skip to content

Commit

Permalink
If logged in with link credentials don't require old password
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrady8800 committed Mar 12, 2024
1 parent e74a98e commit a76117b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { log } from "../services/logging";
import { useState } from "react";
import { useSizeClass } from "../utils/hooks";
import SignUpWithPassword from "../views/SignUpWithPassword";
import { isLoggedIn } from "../models/config/guards";
import { isLoggedInAndInvalidLinkCredentials } from "../models/config/guards";

// TODO DEV-484: expand on string handling and localization, extract to
// a separate JSON file, add capability for client to pass in its own
Expand Down Expand Up @@ -527,7 +527,9 @@ const componentForStep = (state) => {
title: strings.reset.setNewPasswordTitle,
Component: SetNewPassword,
props: {
requireExistingPassword: isLoggedIn(),
requireExistingPassword: isLoggedInAndInvalidLinkCredentials(
state.context
),
},
};

Expand All @@ -536,7 +538,9 @@ const componentForStep = (state) => {
title: strings.reset.setNewPasswordTitle,
Component: SetNewPassword,
props: {
requireExistingPassword: isLoggedIn(),
requireExistingPassword: isLoggedInAndInvalidLinkCredentials(
state.context
),
isLoading: true,
},
};
Expand Down
8 changes: 8 additions & 0 deletions package/src/models/config/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export const isLoggedInOrHasLinkCredentials = (context: AuthContext<any>) => {
return isLoggedIn() || hasLinkQueryParams(context);
};

export const isLoggedInAndInvalidLinkCredentials = (
context: AuthContext<any>
) => {
const validQueryParams =
hasLinkQueryParams(context) && context.query?.isValid;
return isLoggedIn() && !validQueryParams;
};

export const isPasswordReset = (context: AuthContext<any>) => {
return context.config.type === "reset";
};
Expand Down

0 comments on commit a76117b

Please sign in to comment.