diff --git a/Sources/App/RootView.swift b/Sources/App/RootView.swift index 79ab44a..225085a 100644 --- a/Sources/App/RootView.swift +++ b/Sources/App/RootView.swift @@ -9,15 +9,20 @@ struct RootView: View { @State private var pendingDeepLinkSlug: String? var body: some View { - switch auth.status { - case .signedIn: - mainTabs - .onOpenURL { url in handle(url: url) } - .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in - if let url = activity.webpageURL { handle(url: url) } - } - case .unknown, .signedOut, .signingIn, .error: - LoginView() + Group { + switch auth.status { + case .signedIn: + mainTabs + .onOpenURL { url in handle(url: url) } + .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in + if let url = activity.webpageURL { handle(url: url) } + } + case .unknown, .signedOut, .signingIn, .error: + LoginView() + } + } + .task { + await auth.ensureSignedIn() } } diff --git a/Sources/Core/Auth/AuthClient+EnsureSignedIn.swift b/Sources/Core/Auth/AuthClient+EnsureSignedIn.swift new file mode 100644 index 0000000..b927737 --- /dev/null +++ b/Sources/Core/Auth/AuthClient+EnsureSignedIn.swift @@ -0,0 +1,18 @@ +import ManaCore + +extension AuthClient { + /// Stellt sicher, dass der User eingeloggt ist. Nur in DEBUG-Builds + /// aktiv: wenn die Session nach `bootstrap()` `.signedOut` ist, + /// wird automatisch mit den DEBUG-Credentials angemeldet. In + /// Release-Builds No-Op — User muss manuell einloggen. + /// + /// Vorbild: memoro-native — wird in `RootView.task` aufgerufen. + func ensureSignedIn() async { + #if DEBUG + if case .signedOut = status { + Log.auth.notice("DEBUG auto-login: signing in with DebugCredentials") + await signIn(email: DebugCredentials.email, password: DebugCredentials.password) + } + #endif + } +} diff --git a/Sources/Core/Auth/DebugCredentials.swift b/Sources/Core/Auth/DebugCredentials.swift new file mode 100644 index 0000000..9234057 --- /dev/null +++ b/Sources/Core/Auth/DebugCredentials.swift @@ -0,0 +1,17 @@ +#if DEBUG + /// Dev-only Auto-Login-Credentials. + /// + /// **Nur in DEBUG-Builds aktiv** — der ganze File ist hinter + /// `#if DEBUG` gewrapped und wird in Release-Builds (TestFlight/ + /// App-Store) nicht kompiliert. Wird beim App-Start von + /// `AuthClient.ensureSignedIn()` verwendet, falls die Session-Token + /// im Keychain abgelaufen oder leer sind — damit Till während der + /// Entwicklung nicht jedes Mal manuell einloggen muss. + /// + /// Identisches Pattern wie `memoro-native/Sources/Core/Auth/ + /// DebugCredentials.swift`. + enum DebugCredentials { + static let email = "tills95@gmail.com" + static let password = "Aa-123456789" + } +#endif diff --git a/project.yml b/project.yml index 552841b..eb17b87 100644 --- a/project.yml +++ b/project.yml @@ -55,7 +55,7 @@ targets: path: Sources/Resources/Info.plist properties: CFBundleShortVersionString: "0.1.0" - CFBundleVersion: "9" + CFBundleVersion: "10" CFBundleDevelopmentRegion: de CFBundleDisplayName: Cardecky LSApplicationCategoryType: "public.app-category.education" @@ -111,7 +111,7 @@ targets: properties: CFBundleDisplayName: Als Karte speichern CFBundleShortVersionString: "0.1.0" - CFBundleVersion: "9" + CFBundleVersion: "10" NSExtension: NSExtensionPointIdentifier: com.apple.share-services NSExtensionPrincipalClass: $(PRODUCT_MODULE_NAME).ShareViewController @@ -144,7 +144,7 @@ targets: properties: CFBundleDisplayName: Cardecky Widget CFBundleShortVersionString: "0.1.0" - CFBundleVersion: "9" + CFBundleVersion: "10" NSExtension: NSExtensionPointIdentifier: com.apple.widgetkit-extension entitlements: