Skip to content

Commit e821917

Browse files
authored
Merge pull request #241 from brionmario/fix-asgardeo-v2-signup
fix(react): update input variant logic to handle password fields correctly
2 parents 477ffd1 + d9daf5f commit e821917

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

.changeset/ten-guests-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@asgardeo/react': patch
3+
---
4+
5+
Update input variant logic to handle password fields correctly

packages/react/src/components/presentation/SignIn/component-driven/transformer.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ const generateId = (prefix: string): string => {
3131
* Convert simple input type to component variant
3232
*/
3333
const getInputVariant = (type: string, name: string): 'TEXT' | 'EMAIL' | 'PASSWORD' => {
34-
// Check name first (e.g., "password" field name)
35-
const lowerName = name.toLowerCase();
36-
if (lowerName.includes('password')) {
37-
return 'PASSWORD';
38-
}
39-
if (lowerName.includes('email')) {
40-
return 'EMAIL';
41-
}
42-
43-
// Then check type
4434
switch (type.toLowerCase()) {
4535
case 'email':
4636
return 'EMAIL';
@@ -91,16 +81,25 @@ const convertSimpleInputToComponent = (
9181
},
9282
t: UseTranslation['t'],
9383
): EmbeddedFlowComponent => {
94-
const variant = getInputVariant(input.type, input.name);
95-
const label = getInputLabel(input.name, input.type, t);
96-
const placeholder = getInputPlaceholder(input.name, input.type, t);
84+
let fieldType: string = input.type;
85+
86+
// If the field name contains 'password' but type is 'string', change it to 'password'
87+
// TODO: Need to remove this one the following improvement is done.
88+
// Tracker: https://github.com/asgardeo/thunder/issues/725
89+
if (input.name.toLowerCase().includes('password') && input.type.toLowerCase() === 'string') {
90+
fieldType = 'password';
91+
}
92+
93+
const variant: 'TEXT' | 'EMAIL' | 'PASSWORD' = getInputVariant(fieldType, input.name);
94+
const label: string = getInputLabel(input.name, fieldType, t);
95+
const placeholder: string = getInputPlaceholder(input.name, fieldType, t);
9796

9897
return {
9998
id: generateId('input'),
10099
type: EmbeddedFlowComponentType.Input,
101100
variant,
102101
config: {
103-
type: input.type,
102+
type: fieldType,
104103
label,
105104
placeholder,
106105
required: input.required as boolean,
@@ -118,13 +117,19 @@ const convertActionToComponent = (
118117
action: {type: string; id: string},
119118
t: UseTranslation['t'],
120119
): EmbeddedFlowComponent => {
120+
// Normalize action ID for translation lookup (e.g., "google_auth" -> "google")
121+
const normalizedId: string = action.id.replace(/_auth$/, '');
122+
121123
// Use i18n key for button text, fallback to capitalized id
122-
const i18nKey = `elements.buttons.${action.id}`;
123-
let text = t(i18nKey);
124+
const i18nKey: string = `elements.buttons.${normalizedId}`;
125+
let text: string = t(i18nKey);
126+
124127
if (!text || text === i18nKey) {
128+
// Fallback: format the original action ID
125129
text = action.id.replace(/_/g, ' ');
126130
text = text.charAt(0).toUpperCase() + text.slice(1);
127131
}
132+
128133
return {
129134
id: generateId('action'),
130135
type: EmbeddedFlowComponentType.Button,

packages/react/src/components/presentation/SignUp/transformer.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ const generateId = (prefix: string): string => {
3737
* Convert simple input type to component variant
3838
*/
3939
const getInputVariant = (type: string, name: string): 'TEXT' | 'EMAIL' | 'PASSWORD' => {
40-
// Check name first (e.g., "password" field name)
41-
const lowerName = name.toLowerCase();
42-
if (lowerName.includes('password')) {
43-
return 'PASSWORD';
44-
}
45-
if (lowerName.includes('email')) {
46-
return 'EMAIL';
47-
}
48-
4940
// Then check type
5041
switch (type.toLowerCase()) {
5142
case 'email':
@@ -102,6 +93,15 @@ const convertSimpleInputToComponent = (
10293
},
10394
t: UseTranslation['t'],
10495
): EmbeddedFlowComponent => {
96+
let fieldType: string = input.type;
97+
98+
// If the field name contains 'password' but type is 'string', change it to 'password'
99+
// TODO: Need to remove this one the following improvement is done.
100+
// Tracker: https://github.com/asgardeo/thunder/issues/725
101+
if (input.name.toLowerCase().includes('password') && input.type.toLowerCase() === 'string') {
102+
fieldType = 'password';
103+
}
104+
105105
const variant: 'TEXT' | 'EMAIL' | 'PASSWORD' = getInputVariant(input.type, input.name);
106106
const label: string = getInputLabel(input.name, input.type, t);
107107
const placeholder: string = getInputPlaceholder(input.name, input.type, t);
@@ -129,10 +129,15 @@ const convertActionToComponent = (
129129
action: {type: string; id: string},
130130
t: UseTranslation['t'],
131131
): EmbeddedFlowComponent => {
132-
const i18nKey: string = `elements.buttons.${action.id}`;
132+
// Normalize action ID for translation lookup (e.g., "google_auth" -> "google")
133+
const normalizedId: string = action.id.replace(/_auth$/, '');
134+
135+
// Use i18n key for button text, fallback to capitalized id
136+
const i18nKey: string = `elements.buttons.${normalizedId}`;
133137
let text: string = t(i18nKey);
134138

135139
if (!text || text === i18nKey) {
140+
// Fallback: format the original action ID
136141
text = action.id.replace(/_/g, ' ');
137142
text = text.charAt(0).toUpperCase() + text.slice(1);
138143
}

0 commit comments

Comments
 (0)