|
1 | 1 | import SwiftUI |
2 | 2 |
|
3 | 3 | /// Full-screen auth request displayed when a challenge arrives from the Mac. |
| 4 | +/// Styled to match the native macOS passkey "Sign In" dialog. |
4 | 5 | struct AuthRequestView: View { |
5 | 6 | let reason: String |
6 | 7 | let macName: String |
| 8 | + /// Observed from AppState — when true, replace the biometric prompt with a key-invalidated error. |
| 9 | + let keyInvalidated: Bool |
| 10 | + /// Observed from AppState — when true, show a denial message instead of dismissing silently. |
| 11 | + let wasDenied: Bool |
7 | 12 | let onApprove: () -> Void |
8 | 13 | let onDeny: () -> Void |
9 | 14 |
|
10 | 15 | @State private var isAuthenticating = false |
11 | | - @State private var pulse = false |
12 | 16 |
|
13 | 17 | var body: some View { |
14 | 18 | VStack(spacing: 0) { |
15 | | - // Header |
16 | | - VStack(spacing: 16) { |
| 19 | + // Header — mirrors macOS passkey dialog header row |
| 20 | + HStack { |
| 21 | + Label("Sign In", systemImage: "person.badge.key.fill") |
| 22 | + .font(.title2.bold()) |
| 23 | + Spacer() |
| 24 | + Button("Cancel") { |
| 25 | + onDeny() |
| 26 | + } |
| 27 | + .buttonStyle(.bordered) |
| 28 | + } |
| 29 | + .padding(.horizontal, 24) |
| 30 | + .padding(.top, 20) |
| 31 | + .padding(.bottom, 16) |
| 32 | + |
| 33 | + Divider() |
| 34 | + |
| 35 | + Spacer() |
| 36 | + |
| 37 | + // App icon — rounded square, matches Passwords app style |
| 38 | + ZStack { |
| 39 | + RoundedRectangle(cornerRadius: 14) |
| 40 | + .fill(.regularMaterial) |
| 41 | + .frame(width: 64, height: 64) |
| 42 | + .shadow(color: .black.opacity(0.08), radius: 4, x: 0, y: 2) |
| 43 | + |
17 | 44 | Image(systemName: "touchid") |
18 | | - .font(.system(size: 72)) |
| 45 | + .font(.system(size: 36)) |
19 | 46 | .foregroundColor(.accentColor) |
20 | | - .scaleEffect(pulse ? 1.05 : 1.0) |
21 | | - .animation(.easeInOut(duration: 1.0).repeatForever(autoreverses: true), value: pulse) |
22 | | - .onAppear { pulse = true } |
| 47 | + } |
| 48 | + .padding(.bottom, 20) |
23 | 49 |
|
24 | | - Text("Authentication Request") |
25 | | - .font(.title2.bold()) |
| 50 | + if wasDenied { |
| 51 | + // Denied state |
| 52 | + deniedBody |
| 53 | + } else if keyInvalidated { |
| 54 | + // Key invalidated state |
| 55 | + keyInvalidatedBody |
| 56 | + } else { |
| 57 | + // Normal authentication state |
| 58 | + normalBody |
26 | 59 | } |
27 | | - .padding(.top, 48) |
| 60 | + |
| 61 | + Spacer() |
| 62 | + } |
| 63 | + .background(Color(.systemBackground)) |
| 64 | + } |
| 65 | + |
| 66 | + // MARK: - Normal state |
| 67 | + |
| 68 | + @ViewBuilder |
| 69 | + private var normalBody: some View { |
| 70 | + Text("Use Face ID to authenticate?") |
| 71 | + .font(.title3.bold()) |
| 72 | + .multilineTextAlignment(.center) |
| 73 | + .padding(.bottom, 12) |
| 74 | + |
| 75 | + Text("You will be authenticated on \"\(macName)\" for \"\(reason)\".") |
| 76 | + .font(.body) |
| 77 | + .foregroundStyle(.secondary) |
| 78 | + .multilineTextAlignment(.center) |
| 79 | + .padding(.horizontal, 32) |
28 | 80 | .padding(.bottom, 32) |
29 | 81 |
|
30 | | - // Request details |
31 | | - VStack(spacing: 16) { |
32 | | - HStack { |
33 | | - Image(systemName: "desktopcomputer") |
34 | | - .foregroundColor(.accentColor) |
35 | | - Text(macName) |
36 | | - .font(.headline) |
37 | | - Spacer() |
38 | | - } |
| 82 | + // Biometric graphic — pink tint matches macOS passkey dialog |
| 83 | + VStack(spacing: 8) { |
| 84 | + Image(systemName: "touchid") |
| 85 | + .font(.system(size: 80)) |
| 86 | + .foregroundStyle(.pink) |
39 | 87 |
|
40 | | - Divider() |
| 88 | + Text("Continue with Face ID") |
| 89 | + .font(.caption) |
| 90 | + .foregroundStyle(.secondary) |
| 91 | + } |
| 92 | + .padding(.bottom, 40) |
41 | 93 |
|
42 | | - HStack { |
43 | | - Image(systemName: "lock.shield") |
44 | | - .foregroundStyle(.secondary) |
45 | | - Text(reason) |
46 | | - .font(.body) |
47 | | - Spacer() |
| 94 | + // Primary action button |
| 95 | + VStack(spacing: 0) { |
| 96 | + if isAuthenticating { |
| 97 | + ProgressView("Authenticating...") |
| 98 | + .padding() |
| 99 | + .frame(maxWidth: .infinity) |
| 100 | + } else { |
| 101 | + Button { |
| 102 | + isAuthenticating = true |
| 103 | + UIImpactFeedbackGenerator(style: .medium).impactOccurred() |
| 104 | + onApprove() |
| 105 | + } label: { |
| 106 | + Text("Continue with Face ID") |
| 107 | + .font(.headline) |
| 108 | + .frame(maxWidth: .infinity) |
| 109 | + .padding(.vertical, 4) |
48 | 110 | } |
| 111 | + .buttonStyle(.borderedProminent) |
| 112 | + .controlSize(.large) |
| 113 | + .disabled(isAuthenticating) |
49 | 114 | } |
50 | | - .padding() |
51 | | - .background(.regularMaterial) |
52 | | - .clipShape(RoundedRectangle(cornerRadius: 16)) |
53 | | - .padding(.horizontal, 24) |
| 115 | + } |
| 116 | + .padding(.horizontal, 24) |
| 117 | + } |
54 | 118 |
|
55 | | - Spacer() |
| 119 | + // MARK: - Key invalidated state |
56 | 120 |
|
57 | | - // Actions |
58 | | - VStack(spacing: 12) { |
59 | | - if isAuthenticating { |
60 | | - ProgressView("Authenticating...") |
61 | | - .padding() |
62 | | - } else { |
63 | | - Button { |
64 | | - isAuthenticating = true |
65 | | - UIImpactFeedbackGenerator(style: .medium).impactOccurred() |
66 | | - onApprove() |
67 | | - } label: { |
68 | | - Label("Approve with Face ID", systemImage: "faceid") |
69 | | - .font(.headline) |
70 | | - .frame(maxWidth: .infinity) |
71 | | - .padding(.vertical, 4) |
72 | | - } |
73 | | - .buttonStyle(.borderedProminent) |
74 | | - .controlSize(.large) |
75 | | - |
76 | | - Button(role: .destructive) { |
77 | | - UINotificationFeedbackGenerator().notificationOccurred(.warning) |
78 | | - onDeny() |
79 | | - } label: { |
80 | | - Text("Deny") |
81 | | - .frame(maxWidth: .infinity) |
82 | | - } |
83 | | - .buttonStyle(.bordered) |
84 | | - .controlSize(.large) |
85 | | - } |
86 | | - } |
87 | | - .padding(.horizontal, 24) |
88 | | - .padding(.bottom, 32) |
| 121 | + @ViewBuilder |
| 122 | + private var keyInvalidatedBody: some View { |
| 123 | + Image(systemName: "exclamationmark.triangle.fill") |
| 124 | + .font(.system(size: 48)) |
| 125 | + .foregroundStyle(.yellow) |
| 126 | + .padding(.bottom, 12) |
| 127 | + |
| 128 | + Text("Signing key invalid") |
| 129 | + .font(.title3.bold()) |
| 130 | + .padding(.bottom, 8) |
| 131 | + |
| 132 | + Text("Your Face ID / Touch ID enrollment changed since pairing.\n\nOpen Settings → Unpair → Re-pair to restore authentication.") |
| 133 | + .font(.body) |
| 134 | + .foregroundStyle(.secondary) |
| 135 | + .multilineTextAlignment(.center) |
| 136 | + .padding(.horizontal, 32) |
| 137 | + .padding(.bottom, 40) |
| 138 | + |
| 139 | + Button("Dismiss") { |
| 140 | + onDeny() |
| 141 | + } |
| 142 | + .buttonStyle(.bordered) |
| 143 | + .controlSize(.large) |
| 144 | + .frame(maxWidth: .infinity) |
| 145 | + .padding(.horizontal, 24) |
| 146 | + } |
| 147 | + |
| 148 | + // MARK: - Denied state |
| 149 | + |
| 150 | + @ViewBuilder |
| 151 | + private var deniedBody: some View { |
| 152 | + Image(systemName: "xmark.circle.fill") |
| 153 | + .font(.system(size: 48)) |
| 154 | + .foregroundStyle(.red) |
| 155 | + .padding(.bottom, 12) |
| 156 | + |
| 157 | + Text("Request denied") |
| 158 | + .font(.title3.bold()) |
| 159 | + .padding(.bottom, 8) |
| 160 | + |
| 161 | + Text("Your Mac will fall back to password authentication.\nRun sudo again on your Mac if you want to retry.") |
| 162 | + .font(.body) |
| 163 | + .foregroundStyle(.secondary) |
| 164 | + .multilineTextAlignment(.center) |
| 165 | + .padding(.horizontal, 32) |
| 166 | + .padding(.bottom, 40) |
| 167 | + |
| 168 | + Button("Close") { |
| 169 | + onDeny() |
89 | 170 | } |
| 171 | + .buttonStyle(.bordered) |
| 172 | + .controlSize(.large) |
| 173 | + .frame(maxWidth: .infinity) |
| 174 | + .padding(.horizontal, 24) |
90 | 175 | } |
91 | 176 | } |
0 commit comments