diff --git a/services/web/frontend/js/features/settings/components/emails/add-email.tsx b/services/web/frontend/js/features/settings/components/emails/add-email.tsx
index ebe9c00421..6ee2f4f159 100644
--- a/services/web/frontend/js/features/settings/components/emails/add-email.tsx
+++ b/services/web/frontend/js/features/settings/components/emails/add-email.tsx
@@ -245,6 +245,7 @@ function AddEmail() {
@@ -259,12 +260,28 @@ function AddEmail() {
function AddEmailViaSSO({
email,
domainInfo,
+ userInstitutions,
}: {
email: string
domainInfo: DomainInfo
+ userInstitutions: string[]
}) {
if (domainInfo.university.ssoEnabled) {
- // SSO for Commons institution
+ // Check if the user has already linked this institution
+ if (userInstitutions.includes(domainInfo.university.id.toString())) {
+ return (
+
+ This institution is already linked with your account via another
+ email address.
+ >
+ }
+ />
+ )
+ }
return
} else if (
domainInfo.group?.domainCaptureEnabled &&
diff --git a/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx b/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx
index 080cb364e0..0b4546aad2 100644
--- a/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx
+++ b/services/web/test/frontend/features/settings/components/emails/emails-section-add-new-email.test.tsx
@@ -289,6 +289,32 @@ describe('', function () {
await screen.findByRole('button', { name: 'Link accounts and add email' })
})
+ it('prevents user from linking to same SSO institution twice', async function () {
+ fetchMock.get('/user/emails?ensureAffiliation=true', [
+ { email: 'bar@autocomplete.edu', samlProviderId: '1234' },
+ ])
+ render()
+
+ const button = await screen.findByRole('button', {
+ name: 'Add another email',
+ })
+
+ await fetchMock.callHistory.flush(true)
+ fetchMock.removeRoutes().clearHistory()
+ fetchMock.get('express:/institutions/domains', institutionDomainData)
+
+ await userEvent.click(button)
+
+ const input = screen.getByRole('textbox', { name: 'Email' })
+ fireEvent.change(input, {
+ target: { value: 'baz@autocomplete.edu' },
+ })
+
+ await screen.findByText(
+ 'This institution is already linked with your account via another email address.'
+ )
+ })
+
it('adds new email address with existing institution and custom departments', async function () {
const country = 'Germany'
const customDepartment = 'Custom department'