mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-21 12:46:42 +02:00
refactor(auth-ui): SessionManager i18n, shared userAgent util, a11y fixes
- Add locale prop (de/en) to SessionManager with full English translations - Extract duplicated parseUserAgent/getDeviceType to utils/userAgent.ts - Fix hardcoded aria-label in SessionManager refresh button - Add prefers-reduced-motion to PasskeyManager, TwoFactorSetup, SessionExpiredBanner Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3fb1eddc04
commit
3b7b6c9761
7 changed files with 126 additions and 67 deletions
42
packages/shared-auth-ui/src/utils/userAgent.ts
Normal file
42
packages/shared-auth-ui/src/utils/userAgent.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Parse a user agent string to extract browser and OS information.
|
||||
*/
|
||||
export function parseUserAgent(ua: string | null): { browser: string; os: string } {
|
||||
if (!ua) return { browser: '', os: '' };
|
||||
|
||||
let browser = '';
|
||||
let os = '';
|
||||
|
||||
if (ua.includes('Firefox/')) browser = 'Firefox';
|
||||
else if (ua.includes('Edg/')) browser = 'Edge';
|
||||
else if (ua.includes('Chrome/') && !ua.includes('Edg/')) browser = 'Chrome';
|
||||
else if (ua.includes('Safari/') && !ua.includes('Chrome/')) browser = 'Safari';
|
||||
else if (ua.includes('Opera/') || ua.includes('OPR/')) browser = 'Opera';
|
||||
|
||||
if (ua.includes('Windows')) os = 'Windows';
|
||||
else if (ua.includes('Mac OS X') || ua.includes('Macintosh')) os = 'macOS';
|
||||
else if (ua.includes('Linux') && !ua.includes('Android')) os = 'Linux';
|
||||
else if (ua.includes('Android')) os = 'Android';
|
||||
else if (ua.includes('iPhone') || ua.includes('iPad')) os = 'iOS';
|
||||
|
||||
return { browser, os };
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the device type from a user agent string.
|
||||
*/
|
||||
export function getDeviceType(ua: string | null): 'mobile' | 'desktop' | 'tablet' {
|
||||
if (!ua) return 'desktop';
|
||||
if (ua.includes('iPhone') || (ua.includes('Android') && !ua.includes('Tablet'))) return 'mobile';
|
||||
if (ua.includes('iPad') || ua.includes('Tablet')) return 'tablet';
|
||||
return 'desktop';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a user agent string as a display label (e.g. "Chrome · macOS").
|
||||
*/
|
||||
export function formatUserAgent(ua: string | null): string {
|
||||
const { browser, os } = parseUserAgent(ua);
|
||||
const parts = [browser, os].filter(Boolean);
|
||||
return parts.length > 0 ? parts.join(' \u00b7 ') : '';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue