Chris
Chris

Reputation: 2274

Enable Firebase Authentication in Share Extension

I have an app that also has a Share Extension from which I would like to access Firebase but I struggle with permissions...

I tried useUserAccessGroup like this:

Main App:

do {
    try Auth.auth().useUserAccessGroup(UserDefaults.Keys.groupKey)
} catch let error as NSError {
  print("Error changing user access group: %@", error)
}
let uid = Auth.auth().currentUser!.uid
// set user status to logged-in
if let defaults = UserDefaults(suiteName: UserDefaults.Keys.groupKey) {
    defaults.setIsLoggedIn(value: true)
    defaults.setUid(uid: uid)
    defaults.synchronize()
}

Share Extension:

do {
    try Auth.auth().useUserAccessGroup(UserDefaults.Keys.groupKey)
} catch let error as NSError {
  print("Error changing user access group: %@", error)
}
let imageRef = Storage.storage().reference().child("images").child(imageName)
imageRef.putData(imageData, metadata: nil) { (metaData, err) in
...

I guess I am doing something wrong but I don't know what the problem is from reading the Firebase Documentation, so if anyone know the easiest way to get this done I am very grateful!

Upvotes: 2

Views: 453

Answers (1)

Ilya Muradymov
Ilya Muradymov

Reputation: 175

S0. The thoughts is Firebase using for auth mechanism some parts of system that is not accessible from extension. Have you set up Keychain Sharing?

Please take a look at this, this

Pls, keep me updated if succeed or not. Thnx.

Upvotes: 2

Related Questions