1// Copyright © 2019-present 650 Industries. All rights reserved.
2
3#import "EXScopedLocalAuthentication.h"
4#import <LocalAuthentication/LocalAuthentication.h>
5#import <UMCore/UMUtilities.h>
6#import "EXConstantsBinding.h"
7#import <UMConstantsInterface/UMConstantsInterface.h>
8
9@interface EXScopedLocalAuthentication ()
10
11@property (nonatomic, assign) BOOL isInExpoClient;
12
13@end
14
15@implementation EXScopedLocalAuthentication
16
17- (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
18{
19  _isInExpoClient = [((EXConstantsBinding *)[moduleRegistry getModuleImplementingProtocol:@protocol(UMConstantsInterface)]).appOwnership isEqualToString:@"expo"];
20}
21
22UM_EXPORT_METHOD_AS(authenticateAsync,
23                    authenticateAsync:(NSString *)reason
24                    resolve:(UMPromiseResolveBlock)resolve
25                    reject:(UMPromiseRejectBlock)reject)
26{
27  BOOL isInExpoClient = _isInExpoClient;
28  [super authenticateAsync:reason resolve:^(NSDictionary *result) {
29    if (isInExpoClient && [[self class] isFaceIdDevice]) {
30      NSString *usageDescription = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSFaceIDUsageDescription"];
31
32      if (!usageDescription) {
33        NSMutableDictionary *scopedResult = [[NSMutableDictionary alloc] initWithDictionary:result];
34        scopedResult[@"warning"] = @"FaceID is not available in Expo Client. You can use it in a standalone Expo app by providing `NSFaceIDUsageDescription`.";
35        resolve(scopedResult);
36        return;
37      }
38    }
39    resolve(result);
40  } reject:reject];
41}
42
43@end
44