Skip to content

Commit 81271d2

Browse files
jonas-jonasory-bot
authored andcommitted
feat: add "Recover Account" to identifier label
GitOrigin-RevId: 1bd4c27bc2e0a09df7539e16f2385be8b7d298e7
1 parent df9d0e1 commit 81271d2

File tree

9 files changed

+63
-18
lines changed

9 files changed

+63
-18
lines changed

packages/elements-react/src/locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
"misc.or": "oder",
216216
"registration.subtitle": "Registrieren Sie sich mit {parts}.",
217217
"forms.label.forgot-password": "Passwort vergessen?",
218+
"forms.label.recover-account": "Konto wiederherstellen",
218219
"settings.title": "Kontoeinstellungen",
219220
"settings.navigation.title": "Kontoeinstellungen",
220221
"settings.subtitle": "Aktualisieren Sie Ihre Kontoeinstellungen",

packages/elements-react/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
"card.header.description.registration": "Sign up with {identifierLabel}",
245245
"misc.or": "or",
246246
"forms.label.forgot-password": "Forgot Password?",
247+
"forms.label.recover-account": "Recover Account",
247248
"settings.totp.title": "Authenticator App",
248249
"settings.totp.description": "Add a TOTP Authenticator App to your account to improve your account security. Popular Authenticator Apps are LastPass and Google Authenticator",
249250
"settings.totp.info.not-linked": "To enable scan the QR code with your authenticator and enter the code.",

packages/elements-react/src/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
"card.header.description.registration": "Registrarse con {identifierLabel}",
267267
"misc.or": "o",
268268
"forms.label.forgot-password": "¿Olvidaste tu contraseña?",
269+
"forms.label.recover-account": "Recuperar cuenta",
269270
"settings.oidc.info": "Las cuentas conectadas de estos proveedores se pueden utilizar para iniciar sesión en tu cuenta",
270271
"settings.webauthn.info": "Los tokens de hardware se utilizan para la autenticación de segundo factor o como primer factor con las claves de acceso",
271272
"settings.passkey.info": "Administra la configuración de tus claves de acceso",

packages/elements-react/src/locales/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
"card.header.description.registration": "S'inscrire avec {identifierLabel}",
262262
"misc.or": "ou",
263263
"forms.label.forgot-password": "Mot de passe oublié?",
264+
"forms.label.recover-account": "Récupérer le compte",
264265
"settings.lookup_secret.title": "Codes de récupération de sauvegarde (second facteur)",
265266
"settings.lookup_secret.description": "Les codes de récupération sont une sauvegarde sécurisée pour l'authentification à deux facteurs (2FA), vous permettant de retrouver l'accès à votre compte si vous perdez votre appareil 2FA.",
266267
"settings.oidc.title": "Comptes connectés",

packages/elements-react/src/locales/nl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"card.header.parts.password.registration": "",
221221
"card.header.parts.webauthn": "",
222222
"forms.label.forgot-password": "",
223+
"forms.label.recover-account": "",
223224
"login.subtitle": "",
224225
"login.subtitle-refresh": "",
225226
"misc.or": "",

packages/elements-react/src/locales/pl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"card.header.parts.totp": "Twoja aplikacja uwierzytelniająca",
221221
"card.header.parts.lookup_secret": "kod odzyskiwania kopii zapasowej",
222222
"forms.label.forgot-password": "",
223+
"forms.label.recover-account": "",
223224
"login.subtitle": "",
224225
"login.subtitle-refresh": "",
225226
"misc.or": "",

packages/elements-react/src/locales/pt.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"card.header.parts.password.registration": "",
221221
"card.header.parts.webauthn": "",
222222
"forms.label.forgot-password": "",
223+
"forms.label.recover-account": "",
223224
"login.subtitle": "",
224225
"login.subtitle-refresh": "",
225226
"misc.or": "",

packages/elements-react/src/locales/sv.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"card.header.parts.password.registration": "din {identifierLabel} och ett lösenord",
221221
"card.header.parts.webauthn": "en säkerhetsnyckel",
222222
"forms.label.forgot-password": "Glömt Lösenord?",
223+
"forms.label.recover-account": "Återställ Konto",
223224
"login.subtitle": "Logga in med {parts}",
224225
"login.subtitle-refresh": "Bekräfta din identitet med {parts}",
225226
"misc.or": "eller",

packages/elements-react/src/theme/default/components/form/label.tsx

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getNodeLabel,
77
instanceOfUiText,
88
UiNode,
9+
UiNodeInputAttributes,
910
} from "@ory/client-fetch"
1011
import {
1112
messageTestId,
@@ -18,6 +19,7 @@ import {
1819
import { useFormContext } from "react-hook-form"
1920
import { useIntl } from "react-intl"
2021
import { initFlowUrl } from "../../utils/url"
22+
import { useMemo } from "react"
2123

2224
function findResendNode(nodes: UiNode[]) {
2325
return nodes.find(
@@ -37,12 +39,9 @@ export function DefaultLabel({
3739
const intl = useIntl()
3840
const label = getNodeLabel(node)
3941
const { Message } = useComponents()
40-
const { flowType, flow } = useOryFlow()
41-
const config = useOryConfiguration()
42+
const { flow } = useOryFlow()
4243
const { setValue, formState } = useFormContext()
4344

44-
const isPassword = attributes.type === "password"
45-
4645
const resendNode = findResendNode(flow.ui.nodes)
4746

4847
const handleResend = () => {
@@ -65,20 +64,7 @@ export function DefaultLabel({
6564
>
6665
{uiTextToFormattedMessage(label, intl)}
6766
</label>
68-
{isPassword &&
69-
config.project.recovery_enabled &&
70-
flowType === FlowType.Login && (
71-
// TODO: make it possible to override with a custom component
72-
<a
73-
href={initFlowUrl(config.sdk.url, "recovery", flow)}
74-
className="text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline"
75-
>
76-
{intl.formatMessage({
77-
id: "forms.label.forgot-password",
78-
defaultMessage: "Forgot password?",
79-
})}
80-
</a>
81-
)}
67+
<LabelAction attributes={attributes} />
8268
{resendNode?.attributes.node_type === "input" && (
8369
<button
8470
type="submit"
@@ -102,3 +88,54 @@ export function DefaultLabel({
10288
</div>
10389
)
10490
}
91+
92+
type LabelActionProps = {
93+
attributes: UiNodeInputAttributes
94+
}
95+
96+
function LabelAction({ attributes }: LabelActionProps) {
97+
const intl = useIntl()
98+
const { flowType, flow, formState } = useOryFlow()
99+
const config = useOryConfiguration()
100+
101+
const action = useMemo(() => {
102+
if (flowType === FlowType.Login && config.project.recovery_enabled) {
103+
if (formState.current === "provide_identifier" && !flow.refresh) {
104+
if (attributes.name === "identifier") {
105+
return {
106+
message: intl.formatMessage({
107+
id: "forms.label.recover-account",
108+
defaultMessage: "Recover Account",
109+
}),
110+
href: initFlowUrl(config.sdk.url, "recovery", flow),
111+
}
112+
}
113+
} else if (attributes.type === "password") {
114+
return {
115+
message: intl.formatMessage({
116+
id: "forms.label.forgot-password",
117+
defaultMessage: "Forgot password?",
118+
}),
119+
href: initFlowUrl(config.sdk.url, "recovery", flow),
120+
}
121+
}
122+
}
123+
}, [
124+
attributes,
125+
config.project.recovery_enabled,
126+
flow,
127+
flowType,
128+
intl,
129+
config.sdk.url,
130+
formState,
131+
])
132+
133+
return action ? (
134+
<a
135+
href={action.href}
136+
className="text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline"
137+
>
138+
{action.message}
139+
</a>
140+
) : null
141+
}

0 commit comments

Comments
 (0)