Files
supabase/apps/studio/lib/external-identity-providers.test.ts
Saxon Fletcher e491182054 Auth flow improvements (#46967)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES/NO

## What kind of change does this PR introduce?

Bug fix, feature, docs update, ...

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added “Continue with {provider}” sign-in and sign-up flows using
enabled external identity providers.
* Enabled inbound branding to focus a specific provider for customized
sign-in/sign-up experiences.

* **Improvements**
* Refined the sign-in options layout and “last used” tracking for
clearer authentication choices.
* Updated account identity/provider connection experiences (link/unlink
and management UI).

* **Bug Fixes**
  * Fixed hydration mismatches in sign-in and password-related layouts.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-06-18 15:34:56 +08:00

74 lines
2.9 KiB
TypeScript

import { afterEach, describe, expect, test, vi } from 'vitest'
import {
buildProviderAuthRedirect,
getIdentityProviderConfig,
getProviderDisplay,
normalizeIconPath,
} from './external-identity-providers'
describe('external identity providers', () => {
test('normalizes relative icon paths against the dashboard base path', () => {
expect(normalizeIconPath('/img/icons/github-icon.svg')).toBe('/img/icons/github-icon.svg')
expect(normalizeIconPath('img/icons/github-icon.svg')).toBe('/img/icons/github-icon.svg')
expect(normalizeIconPath('https://example.com/icon.svg')).toBe('https://example.com/icon.svg')
})
test('resolves static provider config by provider id or auth provider', () => {
expect(getIdentityProviderConfig('github')?.displayName).toBe('GitHub')
expect(getIdentityProviderConfig('unknown')).toBeUndefined()
})
test('returns display metadata for static, built-in, and fallback providers', () => {
expect(getProviderDisplay('github').displayName).toBe('GitHub')
expect(getProviderDisplay('email').displayName).toBe('Email')
expect(getProviderDisplay('sso:test').displayName).toBe('SSO')
expect(getProviderDisplay('my_provider').displayName).toBe('my provider')
})
test('marks static provider icons as monochrome but not built-in or fallback icons', () => {
expect(getProviderDisplay('github').hasMonochromeIcon).toBe(true)
expect(getProviderDisplay('email').hasMonochromeIcon).toBeUndefined()
expect(getProviderDisplay('sso:test').hasMonochromeIcon).toBeUndefined()
})
describe('buildProviderAuthRedirect', () => {
afterEach(() => {
vi.unstubAllEnvs()
})
test('builds the MFA-check URL against the configured site URL', () => {
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://supabase.com/dashboard')
expect(buildProviderAuthRedirect('github')).toBe(
'https://supabase.com/dashboard/sign-in-mfa?method=github'
)
})
test('URL-encodes custom provider ids in the method param', () => {
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://supabase.com/dashboard')
expect(buildProviderAuthRedirect('custom:example')).toBe(
'https://supabase.com/dashboard/sign-in-mfa?method=custom%3Aexample'
)
})
test('appends an encoded returnTo destination when provided', () => {
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://supabase.com/dashboard')
expect(buildProviderAuthRedirect('custom:example', '/account/me')).toBe(
'https://supabase.com/dashboard/sign-in-mfa?method=custom%3Aexample&returnTo=%2Faccount%2Fme'
)
})
test('uses the current origin on Vercel preview deployments', () => {
vi.stubEnv('NEXT_PUBLIC_VERCEL_ENV', 'preview')
vi.stubEnv('NEXT_PUBLIC_SITE_URL', 'https://supabase.com/dashboard')
expect(buildProviderAuthRedirect('github')).toBe(
`${location.origin}/sign-in-mfa?method=github`
)
})
})
})