Skip to content

Commit 06dc109

Browse files
committed
fix(console): the other two refused account links say why where the signed-in person lands
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a9da547 commit 06dc109

14 files changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/console': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(console): a signed-in person whose account link is refused as already linked to another user, or as unable to link, is told why on the page they land on
7+
8+
Clause-②: yes (widening) — the `@object-ui/i18n` locale packs gain two keys, `auth.login.errors.linkAlreadyLinkedToOtherUser` and `auth.login.errors.linkUnableToLink`, in all eleven shipped locales; no key is renamed or removed.
9+
Metadata-protocol: none
10+
11+
Linking another sign-in to your account can be refused by the server for two more reasons besides a different email: the provider account is already linked to a different user here (`account_already_linked_to_different_user`), or it could not be linked at all (`unable_to_link_account`, chiefly when the sign-in service did not confirm the account's email as verified). Both send you back to the Console sign-in page, which, because you are still signed in, sent you straight on to the console with no word. Each now travels the same way as the email mismatch: the page you land on shows an error toast with its own sentence, in your language, until you close it. The sentence names no other user or email, and nothing from the URL is shown as it came. The refusals themselves are unchanged.

‎ui/apps/console/src/__tests__/App.linkRefusalLanding-33063.test.tsx‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,61 @@ describe('a signed-in person whose link was refused for an email mismatch is tol
210210
expect(sessionStorage.getItem(LINK_REFUSAL_STORAGE_KEY)).toBeNull();
211211
});
212212
});
213+
214+
/**
215+
* objectstack#33498 — better-auth's two other refusals of a signed-in link
216+
* (`linkOAuthAccount`, `oauth2/link-account.mjs`) travel the same way, each
217+
* with its own sentence: `account_already_linked_to_different_user` (the
218+
* provider account belongs to another user here) and `unable_to_link_account`
219+
* (chiefly an untrusted provider that did not assert the email as verified).
220+
*/
221+
describe('the other two link refusals are told where the signed-in person lands (objectstack#33498)', () => {
222+
const SENTENCES = {
223+
account_already_linked_to_different_user: {
224+
en: en.auth.login.errors.linkAlreadyLinkedToOtherUser,
225+
'zh-Hans': zh.auth.login.errors.linkAlreadyLinkedToOtherUser,
226+
},
227+
unable_to_link_account: {
228+
en: en.auth.login.errors.linkUnableToLink,
229+
'zh-Hans': zh.auth.login.errors.linkUnableToLink,
230+
},
231+
email_does_not_match: { en: EN_SENTENCE, 'zh-Hans': ZH_SENTENCE },
232+
} as const;
233+
234+
it('each code has a sentence of its own, in each language', () => {
235+
for (const language of ['en', 'zh-Hans'] as const) {
236+
const shown = Object.values(SENTENCES).map((s) => s[language]);
237+
for (const sentence of shown) expect(typeof sentence).toBe('string');
238+
expect(new Set(shown).size).toBe(shown.length);
239+
}
240+
});
241+
242+
it.each([
243+
['account_already_linked_to_different_user', 'en'],
244+
['account_already_linked_to_different_user', 'zh-Hans'],
245+
['unable_to_link_account', 'en'],
246+
['unable_to_link_account', 'zh-Hans'],
247+
// CONTROL: the first link refusal keeps its own sentence beside the new ones.
248+
['email_does_not_match', 'en'],
249+
['email_does_not_match', 'zh-Hans'],
250+
] as const)('%s under %s: the landing page shows that code’s sentence, and nothing the URL carried', async (code, language) => {
251+
const landed = await arriveSignedIn(
252+
`?error=${code}&error_description=${encodeURIComponent('bob@example.com already owns it')}`,
253+
language,
254+
);
255+
expect(landed).toBe('/');
256+
257+
const notice = await screen.findByTestId('link-refusal-notice', undefined, { timeout: 3000 });
258+
expect(notice.textContent).toBe(SENTENCES[code][language]);
259+
expect(document.body.textContent).not.toContain('bob@example.com');
260+
expect(sessionStorage.getItem(LINK_REFUSAL_STORAGE_KEY)).toBeNull();
261+
});
262+
263+
it('CONTROL: a vendor callback code that is not a link refusal still shows nothing new', async () => {
264+
const landed = await arriveSignedIn('?error=email_not_found');
265+
expect(landed).toBe('/');
266+
await settle();
267+
expect(screen.queryByTestId('link-refusal-notice')).toBeNull();
268+
expect(sessionStorage.getItem(LINK_REFUSAL_STORAGE_KEY)).toBeNull();
269+
});
270+
});

‎ui/apps/console/src/pages/auth/ssoCallbackRefusal.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ const LINK_EMAIL_MISMATCH: RefusalCopy = {
130130
"The account was not linked: its email address doesn't match the one on the account you're signed in with. Link an account that uses the same email address.",
131131
};
132132

133+
const LINK_ALREADY_LINKED_TO_OTHER_USER: RefusalCopy = {
134+
key: 'auth.login.errors.linkAlreadyLinkedToOtherUser',
135+
defaultValue:
136+
'The account was not linked: it is already linked to a different user of this system. Link a different account, or sign in as the user it is linked to and unlink it there first.',
137+
};
138+
139+
const LINK_UNABLE_TO_LINK: RefusalCopy = {
140+
key: 'auth.login.errors.linkUnableToLink',
141+
defaultValue:
142+
'The account could not be linked. Check that its email address is verified with that sign-in service, then try again. If it still fails, ask your administrator.',
143+
};
144+
133145
/**
134146
* Callback `error` code → the sentence for a person who is ALREADY signed in.
135147
*
@@ -142,12 +154,24 @@ const LINK_EMAIL_MISMATCH: RefusalCopy = {
142154
* - `email_does_not_match`: better-auth refused to link a provider account
143155
* whose email differs from the signed-in account's
144156
* (`accountLinking.allowDifferentEmails` is off). No account row is written.
157+
* - `account_already_linked_to_different_user`: the provider account is
158+
* already linked to another user here (its email now matches the
159+
* signed-in account's, or different emails are allowed). Nothing is
160+
* moved. The sentence names no one.
161+
* - `unable_to_link_account`: better-auth would not link it, chiefly because
162+
* a provider that is not trusted did not assert the email as verified
163+
* (also when linking is turned off, or the account row cannot be written).
164+
*
165+
* All three are `linkOAuthAccount`'s refusals (better-auth
166+
* `oauth2/link-account.mjs`), redirected by the callback to the error URL.
145167
*
146168
* Only these codes travel; any other `error` a signed-in person arrives with
147169
* is left where it was, and nothing from the URL is ever shown as it came.
148170
*/
149171
const SIGNED_IN_LINK_REFUSALS: Readonly<Record<string, RefusalCopy>> = {
150172
email_does_not_match: LINK_EMAIL_MISMATCH,
173+
account_already_linked_to_different_user: LINK_ALREADY_LINKED_TO_OTHER_USER,
174+
unable_to_link_account: LINK_UNABLE_TO_LINK,
151175
};
152176

153177
/** Whether `code` is a link refusal a signed-in person is told about where they land. */

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,6 +3008,8 @@ const ar = {
30083008
ssoBackToConsole: "العودة إلى وحدة التحكم",
30093009
ssoSwitchAccountHint: "يفتح «تبديل الحساب» خدمة تسجيل الدخول في علامة تبويب جديدة ويسجّل خروجك هناك. ثم سجّل الدخول هنا مرة أخرى بحساب لديه صلاحية الوصول.",
30103010
linkEmailMismatch: "لم يتم ربط الحساب: عنوان بريده الإلكتروني لا يطابق عنوان البريد الإلكتروني للحساب الذي سجّلت الدخول به. اربط حسابًا يستخدم عنوان البريد الإلكتروني نفسه.",
3011+
linkAlreadyLinkedToOtherUser: "لم يتم ربط الحساب: إنه مرتبط بالفعل بمستخدم آخر في هذا النظام. اربط حسابًا آخر، أو سجّل الدخول باسم المستخدم المرتبط به وألغِ الربط من هناك أولًا.",
3012+
linkUnableToLink: "تعذّر ربط الحساب. تأكد من أن عنوان بريده الإلكتروني مُتحقَّق منه لدى خدمة تسجيل الدخول تلك، ثم أعد المحاولة. إذا استمر الفشل، فاتصل بالمسؤول.",
30113013
twoFactorInvalidCode: "هذا الرمز غير صالح. تحقّق من تطبيق المصادقة وحاول مرة أخرى.",
30123014
twoFactorInvalidBackupCode: "رمز النسخ الاحتياطي هذا غير صالح أو سبق استخدامه.",
30133015
twoFactorTooManyAttempts: "رموز غير صحيحة كثيرة جدًا. سجّل الدخول بكلمة المرور مرة أخرى.",

‎ui/packages/i18n/src/locales/de.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,8 @@ const de = {
27342734
ssoBackToConsole: "Zurück zur Konsole",
27352735
ssoSwitchAccountHint: "Konto wechseln öffnet Ihren Anmeldedienst in einem neuen Tab und meldet Sie dort ab. Melden Sie sich anschließend hier erneut mit einem Konto an, das Zugriff hat.",
27362736
linkEmailMismatch: "Das Konto wurde nicht verknüpft: Seine E-Mail-Adresse stimmt nicht mit der des Kontos überein, mit dem Sie angemeldet sind. Verknüpfen Sie ein Konto mit derselben E-Mail-Adresse.",
2737+
linkAlreadyLinkedToOtherUser: "Das Konto wurde nicht verknüpft: Es ist bereits mit einem anderen Benutzer dieses Systems verknüpft. Verknüpfen Sie ein anderes Konto, oder melden Sie sich als der Benutzer an, mit dem es verknüpft ist, und heben Sie die Verknüpfung dort zuerst auf.",
2738+
linkUnableToLink: "Das Konto konnte nicht verknüpft werden. Prüfen Sie, ob seine E-Mail-Adresse bei diesem Anmeldedienst bestätigt ist, und versuchen Sie es erneut. Wenn es weiterhin fehlschlägt, wenden Sie sich an Ihren Administrator.",
27372739
twoFactorInvalidCode: "Dieser Code ist ungültig. Prüfen Sie Ihre Authenticator-App und versuchen Sie es erneut.",
27382740
twoFactorInvalidBackupCode: "Dieser Backup-Code ist ungültig oder wurde bereits verwendet.",
27392741
twoFactorTooManyAttempts: "Zu viele falsche Codes. Melden Sie sich erneut mit Ihrem Passwort an.",

‎ui/packages/i18n/src/locales/en.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,9 @@ const en = {
33943394
ssoSwitchAccountHint: "Switch account opens your sign-in service in a new tab and signs you out there. Then sign in here again with an account that has access.",
33953395
// A signed-in person's link refused by the callback (`email_does_not_match`), shown where they land.
33963396
linkEmailMismatch: "The account was not linked: its email address doesn't match the one on the account you're signed in with. Link an account that uses the same email address.",
3397+
// objectstack#33498 — the vendor's other two link refusals, shown the same way.
3398+
linkAlreadyLinkedToOtherUser: "The account was not linked: it is already linked to a different user of this system. Link a different account, or sign in as the user it is linked to and unlink it there first.",
3399+
linkUnableToLink: "The account could not be linked. Check that its email address is verified with that sign-in service, then try again. If it still fails, ask your administrator.",
33973400
// objectstack#29105 — refusals of the two-factor sign-in step, by the
33983401
// server's code (`signInRefusalMessages`).
33993402
twoFactorInvalidCode: 'That code is not valid. Check your authenticator app and try again.',

‎ui/packages/i18n/src/locales/es.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,8 @@ const es = {
28042804
ssoBackToConsole: "Volver a la consola",
28052805
ssoSwitchAccountHint: "Cambiar de cuenta abre tu servicio de inicio de sesión en una pestaña nueva y cierra allí tu sesión. Después, vuelve a iniciar sesión aquí con una cuenta que tenga acceso.",
28062806
linkEmailMismatch: "La cuenta no se vinculó: su dirección de correo electrónico no coincide con la de la cuenta con la que iniciaste sesión. Vincula una cuenta que use la misma dirección de correo electrónico.",
2807+
linkAlreadyLinkedToOtherUser: "La cuenta no se vinculó: ya está vinculada a otro usuario de este sistema. Vincula otra cuenta, o inicia sesión como el usuario al que está vinculada y desvincúlala allí primero.",
2808+
linkUnableToLink: "No se pudo vincular la cuenta. Comprueba que su dirección de correo electrónico esté verificada en ese servicio de inicio de sesión y vuelve a intentarlo. Si sigue fallando, contacta con tu administrador.",
28072809
twoFactorInvalidCode: "Ese código no es válido. Revise su aplicación de autenticación e inténtelo de nuevo.",
28082810
twoFactorInvalidBackupCode: "Ese código de respaldo no es válido o ya se ha utilizado.",
28092811
twoFactorTooManyAttempts: "Demasiados códigos incorrectos. Vuelva a iniciar sesión con su contraseña.",

‎ui/packages/i18n/src/locales/fr.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,8 @@ const fr = {
28002800
ssoBackToConsole: "Retour à la console",
28012801
ssoSwitchAccountHint: "Changer de compte ouvre votre service de connexion dans un nouvel onglet et vous y déconnecte. Reconnectez-vous ensuite ici avec un compte qui a accès.",
28022802
linkEmailMismatch: "Le compte n'a pas été lié : son adresse e-mail ne correspond pas à celle du compte avec lequel vous êtes connecté. Liez un compte qui utilise la même adresse e-mail.",
2803+
linkAlreadyLinkedToOtherUser: "Le compte n'a pas été lié : il est déjà lié à un autre utilisateur de ce système. Liez un autre compte, ou connectez-vous en tant qu'utilisateur auquel il est lié et supprimez d'abord la liaison depuis ce compte.",
2804+
linkUnableToLink: "Le compte n'a pas pu être lié. Vérifiez que son adresse e-mail est confirmée auprès de ce service de connexion, puis réessayez. Si le problème persiste, contactez votre administrateur.",
28032805
twoFactorInvalidCode: "Ce code n'est pas valide. Vérifiez votre application d'authentification et réessayez.",
28042806
twoFactorInvalidBackupCode: "Ce code de secours n'est pas valide ou a déjà été utilisé.",
28052807
twoFactorTooManyAttempts: "Trop de codes incorrects. Reconnectez-vous avec votre mot de passe.",

‎ui/packages/i18n/src/locales/ja.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,8 @@ const ja = {
27362736
ssoBackToConsole: "コンソールに戻る",
27372737
ssoSwitchAccountHint: "「アカウントを切り替える」を選ぶと、新しいタブでサインインサービスが開き、そこでサインアウトします。その後、アクセス権のあるアカウントでここから再度サインインしてください。",
27382738
linkEmailMismatch: "アカウントはリンクされませんでした。そのメールアドレスが、サインイン中のアカウントのメールアドレスと一致しません。同じメールアドレスを使用するアカウントをリンクしてください。",
2739+
linkAlreadyLinkedToOtherUser: "アカウントはリンクされませんでした。このシステムの別のユーザーに既にリンクされています。別のアカウントをリンクするか、リンク先のユーザーとしてサインインし、先にそちらでリンクを解除してください。",
2740+
linkUnableToLink: "アカウントをリンクできませんでした。そのメールアドレスがそのサインインサービスで確認済みであることを確かめてから、もう一度お試しください。それでも失敗する場合は、管理者にお問い合わせください。",
27392741
twoFactorInvalidCode: "コードが無効です。認証アプリを確認して、もう一度お試しください。",
27402742
twoFactorInvalidBackupCode: "このバックアップコードは無効か、すでに使用されています。",
27412743
twoFactorTooManyAttempts: "誤ったコードの入力が多すぎます。パスワードでもう一度サインインしてください。",

‎ui/packages/i18n/src/locales/ko.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,8 @@ const ko = {
27342734
ssoBackToConsole: "콘솔로 돌아가기",
27352735
ssoSwitchAccountHint: "계정 전환을 누르면 새 탭에서 로그인 서비스가 열리고 그곳에서 로그아웃됩니다. 그런 다음 액세스 권한이 있는 계정으로 여기에서 다시 로그인하세요.",
27362736
linkEmailMismatch: "계정이 연결되지 않았습니다. 해당 계정의 이메일 주소가 현재 로그인한 계정의 이메일 주소와 일치하지 않습니다. 같은 이메일 주소를 사용하는 계정을 연결하세요.",
2737+
linkAlreadyLinkedToOtherUser: "계정이 연결되지 않았습니다. 이 시스템의 다른 사용자에게 이미 연결되어 있습니다. 다른 계정을 연결하거나, 해당 계정이 연결된 사용자로 로그인하여 먼저 그곳에서 연결을 해제하세요.",
2738+
linkUnableToLink: "계정을 연결할 수 없습니다. 해당 계정의 이메일 주소가 그 로그인 서비스에서 인증되었는지 확인한 후 다시 시도하세요. 계속 실패하면 관리자에게 문의하세요.",
27372739
twoFactorInvalidCode: "코드가 올바르지 않습니다. 인증 앱을 확인한 후 다시 시도하세요.",
27382740
twoFactorInvalidBackupCode: "백업 코드가 올바르지 않거나 이미 사용되었습니다.",
27392741
twoFactorTooManyAttempts: "잘못된 코드를 너무 많이 입력했습니다. 비밀번호로 다시 로그인하세요.",

0 commit comments

Comments
 (0)