Skip to content

Commit

Permalink
Add password email notice
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrw committed Nov 25, 2023
1 parent fd7fb40 commit 2bbdd24
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
23 changes: 23 additions & 0 deletions package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const strings = {
},

// strategies
password: {
checkEmail: "Check your email for a link to set your password",
},
email: {
link: {
title: "Email me a link",
Expand Down Expand Up @@ -233,6 +236,18 @@ const componentForStep = (state) => {
isLogin: type === "login",
},
};
case "selectFirstFactor.showEmailSent":
return {
title: strings[type].title,
Component: SelectFactor,
props: {
isCompact: state.context.config.compact,
flow: state.context.config.flow,
isSecondFactor: false,
tenantId: state.context.tenantId,
isLogin: type === "login",
},
};

// SelectFactor flow for second factor,
// with password possibly inlined
Expand Down Expand Up @@ -401,6 +416,14 @@ const componentForStep = (state) => {
title: strings[type].done,
Component: Success,
};
case "password.showEmailSent":
return {
title: strings[type].password.checkEmail,
Component: EmailLinkSent,
props: {
message: state.context.view.message,
},
};

// TOTP flow
case "useTotpCode.showForm": {
Expand Down
13 changes: 13 additions & 0 deletions package/src/models/views/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ const passwordConfig: AuthMachineConfig = {
target: "showForm",
},
onDone: [
// If the user did not have a password previously, let them
// know that an email was sent to set their password.
{
cond: "passwordResetEmailSent",
actions: "setEmailSentMessage",
target: "showEmailSent",
},
// On success, proceed to second factor if required
{
actions: "setAllowedSecondFactors",
Expand All @@ -87,6 +94,12 @@ const passwordConfig: AuthMachineConfig = {
showPasswordSet: {
type: "final",
},
// Show that an email was sent, in the case where the user did not have a password
showEmailSent: {
on: {
back: "showForm",
},
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion package/src/views/AlreadyLoggedIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
*/
const AlreadyLoggedIn = () => {
return <p>You're logged in!</p>;
return <p>You're logged in</p>;
};

export default AlreadyLoggedIn;
2 changes: 1 addition & 1 deletion package/src/views/Success.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Success = ({ redirect }) => {
return (
<>
<p>
You're logged in!
You're logged in
{redirect &&
"If you aren't redirected, click the button below to continue."}
</p>
Expand Down

0 comments on commit 2bbdd24

Please sign in to comment.