import SwiftUI import JobleyKit /// Signing in, for the curator and moderators: a passkey, nothing else. A first passkey is added /// with the one-time setup link the curator (or, for the curator, the setup endpoint) gives you. public struct PasskeySignIn: View { @ObservedObject var curator: CuratorModel @State private var setupLink = "" public init(curator: CuratorModel) { self.curator = curator } public var body: some View { VStack(alignment: .leading, spacing: 12) { Button { Task { await curator.signInWithPasskey() } } label: { Label(curator.signingIn ? "Waiting for your passkey…" : "Sign in with passkey", systemImage: "person.badge.key") } .buttonStyle(PrimaryButtonStyle()) .disabled(curator.signingIn) Divider().padding(.vertical, 4) Text("First time? Paste the setup link you were given, then add a passkey on this device.") .font(.callout).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true) TextField("Setup link", text: $setupLink, prompt: Text("https://jobley.ai/passkey/#…")) .textFieldStyle(.roundedBorder) .autocorrectionDisabled() #if os(iOS) .textInputAutocapitalization(.never) .keyboardType(.URL) #endif Button("Add a passkey") { Task { if await curator.addFirstPasskey(setupLink: setupLink) { setupLink = "" } } } .disabled(setupLink.isEmpty || curator.signingIn) if let error = curator.error { Text(error).font(.caption).foregroundStyle(Theme.danger).fixedSize(horizontal: false, vertical: true) } } } } /// The signed-in person's passkeys: add another (the way to recover) and remove any but the last. public struct PasskeyList: View { @ObservedObject var curator: CuratorModel public init(curator: CuratorModel) { self.curator = curator } public var body: some View { Group { ForEach(curator.passkeys) { passkey in HStack { VStack(alignment: .leading, spacing: 2) { Text(passkey.name ?? "Passkey") Text(passkey.lastUsedAt.map { "Last used \(APIDate.short($0))" } ?? "Added \(APIDate.short(passkey.createdAt))") .font(.caption).foregroundStyle(.secondary) } Spacer() if curator.passkeys.count > 1 { Button("Remove", role: .destructive) { Task { await curator.removePasskey(passkey) } } } } } Button { Task { await curator.addAnotherPasskey() } } label: { Label(curator.signingIn ? "Waiting for your passkey…" : "Add a passkey", systemImage: "plus") } .disabled(curator.signingIn) if let error = curator.error { Text(error).font(.caption).foregroundStyle(Theme.danger) } } .task { await curator.loadPasskeys() } } }