set different app group names for macos and ios
This commit is contained in:
@ -14,10 +14,14 @@ public class PersistentContainer: NSPersistentContainer {
|
||||
|
||||
// Store the sqlite file in the app group container.
|
||||
// This allows shared access for app and app extensions.
|
||||
let appGroupID = "group.app.omnivoreapp"
|
||||
// TODO: fix this for macos...it's crashing locally when using forSecurityApplicationGroupIdentifier
|
||||
#if os(iOS)
|
||||
let appGroupID = "group.app.omnivoreapp"
|
||||
#else
|
||||
let appGroupID = "QJF2XZ86HB.app.omnivore.app"
|
||||
#endif
|
||||
let appGroupContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)
|
||||
let appGroupContainerURL = appGroupContainer?.appendingPathComponent("store.sqlite")
|
||||
|
||||
container.persistentStoreDescriptions.first!.url = appGroupContainerURL
|
||||
|
||||
container.viewContext.automaticallyMergesChangesFromParent = true
|
||||
|
||||
@ -11,7 +11,10 @@ public enum GoogleAuthResponse {
|
||||
|
||||
extension Authenticator {
|
||||
public func handleGoogleAuth() async -> GoogleAuthResponse {
|
||||
let idToken = try? await googleSignIn()
|
||||
let idToken = await withCheckedContinuation { continuation in
|
||||
googleSignIn { continuation.resume(returning: $0) }
|
||||
}
|
||||
|
||||
guard let idToken = idToken else { return .loginError(error: .unauthorized) }
|
||||
|
||||
do {
|
||||
@ -47,37 +50,34 @@ extension Authenticator {
|
||||
}
|
||||
}
|
||||
|
||||
func googleSignIn() async throws -> String {
|
||||
func googleSignIn(completion: @escaping (String?) -> Void) {
|
||||
#if os(iOS)
|
||||
let presenting = presentingViewController()
|
||||
#else
|
||||
let presenting = await NSApplication.shared.mainWindow
|
||||
let presenting = NSApplication.shared.windows.first
|
||||
#endif
|
||||
|
||||
guard let presenting = presenting else {
|
||||
throw LoginError.unknown
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
let clientID = "\(AppKeys.sharedInstance?.iosClientGoogleId ?? "").apps.googleusercontent.com"
|
||||
|
||||
let clientID = "\(AppKeys.sharedInstance?.iosClientGoogleId ?? "").apps.googleusercontent.com"
|
||||
GIDSignIn.sharedInstance.signIn(
|
||||
with: GIDConfiguration(clientID: clientID),
|
||||
presenting: presenting
|
||||
) { user, error in
|
||||
guard let user = user, error == nil else {
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
|
||||
GIDSignIn.sharedInstance.signIn(
|
||||
with: GIDConfiguration(clientID: clientID),
|
||||
presenting: presenting
|
||||
) { user, error in
|
||||
guard let user = user, error == nil else {
|
||||
continuation.resume(throwing: LoginError.unauthorized)
|
||||
user.authentication.do { authentication, error in
|
||||
guard let idToken = authentication?.idToken, error == nil else {
|
||||
completion(nil)
|
||||
return
|
||||
}
|
||||
|
||||
user.authentication.do { authentication, error in
|
||||
guard let idToken = authentication?.idToken, error == nil else {
|
||||
continuation.resume(throwing: LoginError.unauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
continuation.resume(returning: idToken)
|
||||
}
|
||||
completion(idToken)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user