From ac0a4c375662ce815547ef9b92e934eee2a8d394 Mon Sep 17 00:00:00 2001
From: Kyle Spearrin <kyle.spearrin@gmail.com>
Date: Thu, 21 Jul 2016 21:33:27 -0400
Subject: [PATCH] extension alert error when not logged in

---
 src/iOS.Extension/LoadingViewController.cs | 23 +++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/iOS.Extension/LoadingViewController.cs b/src/iOS.Extension/LoadingViewController.cs
index 6d07185f0..80852118d 100644
--- a/src/iOS.Extension/LoadingViewController.cs
+++ b/src/iOS.Extension/LoadingViewController.cs
@@ -17,6 +17,8 @@ using MobileCoreServices;
 using Plugin.Settings.Abstractions;
 using Plugin.Connectivity;
 using Plugin.Fingerprint;
+using Bit.iOS.Core.Utilities;
+using Bit.App.Resources;
 
 namespace Bit.iOS.Extension
 {
@@ -67,6 +69,17 @@ namespace Bit.iOS.Extension
         {
             base.ViewDidAppear(animated);
 
+            var authService = Resolver.Resolve<IAuthService>();
+            if(!authService.IsAuthenticated)
+            {
+                var alert = Dialogs.CreateAlert(null, "You must log into the main bitwarden app before you can use the extension.", AppResources.Ok, (a) =>
+                {
+                    CompleteRequest();
+                });
+                PresentViewController(alert, true, null);
+                return;
+            }
+
             var lockService = Resolver.Resolve<ILockService>();
             var lockType = lockService.GetLockType(false);
             switch(lockType)
@@ -86,6 +99,15 @@ namespace Bit.iOS.Extension
             }
         }
 
+        private void CompleteRequest()
+        {
+            var resultsProvider = new NSItemProvider(null, UTType.PropertyList);
+            var resultsItem = new NSExtensionItem { Attachments = new NSItemProvider[] { resultsProvider } };
+            var returningItems = new NSExtensionItem[] { resultsItem };
+
+            ExtensionContext.CompleteRequest(returningItems, null);
+        }
+
         public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
         {
             var navController = segue.DestinationViewController as UINavigationController;
@@ -332,6 +354,5 @@ namespace Bit.iOS.Extension
 
             return default(T);
         }
-
     }
 }
\ No newline at end of file