Skip to content

Commit 777b6c3

Browse files
committed
feat: start using contentpass sdk in expo app
1 parent 7acdee9 commit 777b6c3

File tree

12 files changed

+146
-23
lines changed

12 files changed

+146
-23
lines changed

expoExample/App.tsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

expoExample/android/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ android {
9393
targetSdkVersion rootProject.ext.targetSdkVersion
9494
versionCode 1
9595
versionName "1.0.0"
96+
manifestPlaceholders = [
97+
appAuthRedirectScheme: 'de.contentpass.demo'
98+
]
9699
}
97100
signingConfigs {
98101
debug {

expoExample/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { registerRootComponent } from 'expo';
22

3-
import App from './App';
3+
import App from './src/App';
44

55
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
66
// It also ensures that whether you load the app in Expo Go or in a native build,

expoExample/ios/ContentpassExpoExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
);
274274
inputPaths = (
275275
"${PODS_ROOT}/Target Support Files/Pods-ContentpassExpoExample/Pods-ContentpassExpoExample-resources.sh",
276+
"${PODS_CONFIGURATION_BUILD_DIR}/AppAuth/AppAuthCore_Privacy.bundle",
276277
"${PODS_CONFIGURATION_BUILD_DIR}/EXConstants/EXConstants.bundle",
277278
"${PODS_CONFIGURATION_BUILD_DIR}/EXConstants/ExpoConstants_privacy.bundle",
278279
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoFileSystem/ExpoFileSystem_privacy.bundle",
@@ -284,6 +285,7 @@
284285
);
285286
name = "[CP] Copy Pods Resources";
286287
outputPaths = (
288+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AppAuthCore_Privacy.bundle",
287289
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EXConstants.bundle",
288290
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoConstants_privacy.bundle",
289291
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoFileSystem_privacy.bundle",
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#import <React/RCTLinkingManager.h>
2+
#import "RNAppAuthAuthorizationFlowManager.h"
13
#import <RCTAppDelegate.h>
24
#import <UIKit/UIKit.h>
35
#import <Expo/Expo.h>
46

5-
@interface AppDelegate : EXAppDelegateWrapper
7+
@interface AppDelegate : EXAppDelegateWrapper <RNAppAuthAuthorizationFlowManager>
8+
@property(nonatomic, weak) id<RNAppAuthAuthorizationFlowManagerDelegate> authorizationFlowManagerDelegate;
69

710
@end

expoExample/ios/Podfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
PODS:
2+
- AppAuth (1.7.6):
3+
- AppAuth/Core (= 1.7.6)
4+
- AppAuth/ExternalUserAgent (= 1.7.6)
5+
- AppAuth/Core (1.7.6)
6+
- AppAuth/ExternalUserAgent (1.7.6):
7+
- AppAuth/Core
28
- boost (1.84.0)
39
- DoubleConversion (1.1.6)
410
- EXConstants (17.0.3):
@@ -1277,6 +1283,11 @@ PODS:
12771283
- ReactCommon/turbomodule/bridging
12781284
- ReactCommon/turbomodule/core
12791285
- Yoga
1286+
- react-native-app-auth (8.0.1):
1287+
- AppAuth (>= 1.7.6)
1288+
- React-Core
1289+
- react-native-encrypted-storage (4.0.3):
1290+
- React-Core
12801291
- React-nativeconfig (0.76.3)
12811292
- React-NativeModulesApple (0.76.3):
12821293
- glog
@@ -1592,6 +1603,8 @@ DEPENDENCIES:
15921603
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
15931604
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
15941605
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
1606+
- react-native-app-auth (from `../node_modules/react-native-app-auth`)
1607+
- react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`)
15951608
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
15961609
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
15971610
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -1623,6 +1636,7 @@ DEPENDENCIES:
16231636

16241637
SPEC REPOS:
16251638
trunk:
1639+
- AppAuth
16261640
- SocketRocket
16271641

16281642
EXTERNAL SOURCES:
@@ -1711,6 +1725,10 @@ EXTERNAL SOURCES:
17111725
:path: "../node_modules/react-native/ReactCommon"
17121726
React-microtasksnativemodule:
17131727
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
1728+
react-native-app-auth:
1729+
:path: "../node_modules/react-native-app-auth"
1730+
react-native-encrypted-storage:
1731+
:path: "../node_modules/react-native-encrypted-storage"
17141732
React-nativeconfig:
17151733
:path: "../node_modules/react-native/ReactCommon"
17161734
React-NativeModulesApple:
@@ -1769,6 +1787,7 @@ EXTERNAL SOURCES:
17691787
:path: "../node_modules/react-native/ReactCommon/yoga"
17701788

17711789
SPEC CHECKSUMS:
1790+
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
17721791
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
17731792
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
17741793
EXConstants: dd2fe64c6cdb1383b694c309a63028a8e9f2be6d
@@ -1811,6 +1830,8 @@ SPEC CHECKSUMS:
18111830
React-logger: 26155dc23db5c9038794db915f80bd2044512c2e
18121831
React-Mapbuffer: ad1ba0205205a16dbff11b8ade6d1b3959451658
18131832
React-microtasksnativemodule: e771eb9eb6ace5884ee40a293a0e14a9d7a4343c
1833+
react-native-app-auth: 79605228ffe689f63ad5b046319f5e154e3e96c2
1834+
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
18141835
React-nativeconfig: aeed6e2a8ac02b2df54476afcc7c663416c12bf7
18151836
React-NativeModulesApple: c5b7813da94136f50ef084fa1ac077332dcfc658
18161837
React-perflogger: 6afb7eebf7d9521cc70481688ccddf212970e9d3

expoExample/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"expo": "~52.0.11",
1212
"expo-status-bar": "~2.0.0",
1313
"react": "18.3.1",
14-
"react-native": "0.76.3"
14+
"react-native": "0.76.3",
15+
"react-native-app-auth": "^8.0.1",
16+
"react-native-encrypted-storage": "^4.0.3"
1517
},
1618
"devDependencies": {
1719
"@babel/core": "^7.25.2",

expoExample/src/App.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { StyleSheet, View } from 'react-native';
2+
import { ContentpassSdkProvider } from './ContentpassContext';
3+
import ContentpassUsage from './ContentpassUsage';
4+
5+
const styles = StyleSheet.create({
6+
container: {
7+
flex: 1,
8+
alignItems: 'center',
9+
justifyContent: 'center',
10+
},
11+
box: {
12+
width: 60,
13+
height: 60,
14+
marginVertical: 20,
15+
},
16+
});
17+
18+
export default function App() {
19+
return (
20+
<ContentpassSdkProvider>
21+
<View style={styles.container}>
22+
<ContentpassUsage />
23+
</View>
24+
</ContentpassSdkProvider>
25+
);
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { createContext, useContext, useEffect, useState } from 'react';
2+
import { Contentpass } from 'react-native-contentpass';
3+
import { contentpassConfig } from './contentpassConfig';
4+
5+
const contentpassSdkContext = createContext<Contentpass | undefined>(undefined);
6+
7+
export const ContentpassSdkProvider = ({
8+
children,
9+
}: {
10+
children: React.ReactNode;
11+
}) => {
12+
const [contentpassSdk, setContentpassSdk] = useState<
13+
Contentpass | undefined
14+
>();
15+
16+
useEffect(() => {
17+
const contentpass = new Contentpass(contentpassConfig);
18+
19+
setContentpassSdk(contentpass);
20+
}, []);
21+
22+
if (!contentpassSdk) {
23+
return null;
24+
}
25+
26+
return (
27+
<contentpassSdkContext.Provider value={contentpassSdk}>
28+
{children}
29+
</contentpassSdkContext.Provider>
30+
);
31+
};
32+
33+
export const useContentpassSdk = () => {
34+
const contentpassSdk = useContext(contentpassSdkContext);
35+
36+
if (!contentpassSdk) {
37+
throw new Error(
38+
'useContentpassSdk must be used within a ContentpassSdkProvider'
39+
);
40+
}
41+
42+
return contentpassSdk;
43+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useContentpassSdk } from './ContentpassContext';
2+
import { Button, Text } from 'react-native';
3+
import { useState } from 'react';
4+
import type { AuthenticateResult } from 'react-native-contentpass';
5+
6+
export default function ContentpassUsage() {
7+
const [authResult, setAuthResult] = useState<
8+
AuthenticateResult | undefined
9+
>();
10+
const contentpassSdk = useContentpassSdk();
11+
12+
const authenticate = async () => {
13+
const result = await contentpassSdk.authenticate();
14+
setAuthResult(result);
15+
};
16+
17+
return (
18+
<>
19+
<Button title={'Authenticate'} onPress={authenticate} />
20+
<Text>Result: {JSON.stringify(authResult)}</Text>
21+
</>
22+
);
23+
}

0 commit comments

Comments
 (0)