Skip to content

Commit 057928c

Browse files
authored
Update Example Android build, link to local source (#749)
1 parent 258cb6d commit 057928c

File tree

7 files changed

+82
-26
lines changed

7 files changed

+82
-26
lines changed

Example/App.js

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import React, { useState, useCallback, useMemo } from 'react';
2-
import { UIManager, Alert } from 'react-native';
3-
import { authorize, refresh, revoke, prefetchConfiguration } from 'react-native-app-auth';
4-
import { Page, Button, ButtonContainer, Form, FormLabel, FormValue, Heading } from './components';
5-
1+
import React, {useState, useCallback, useMemo} from 'react';
2+
import {UIManager, Alert} from 'react-native';
3+
import {
4+
authorize,
5+
refresh,
6+
revoke,
7+
prefetchConfiguration,
8+
} from 'react-native-app-auth';
9+
import {
10+
Page,
11+
Button,
12+
ButtonContainer,
13+
Form,
14+
FormLabel,
15+
FormValue,
16+
Heading,
17+
} from './components';
618

719
const configs = {
820
identityserver: {
@@ -31,15 +43,15 @@ const configs = {
3143
// tokenEndpoint: 'https://samples.auth0.com/oauth/token',
3244
// revocationEndpoint: 'https://samples.auth0.com/oauth/revoke'
3345
// }
34-
}
46+
},
3547
};
3648

3749
const defaultAuthState = {
3850
hasLoggedInOnce: false,
3951
provider: '',
4052
accessToken: '',
4153
accessTokenExpirationDate: '',
42-
refreshToken: ''
54+
refreshToken: '',
4355
};
4456

4557
const App = () => {
@@ -48,7 +60,7 @@ const App = () => {
4860
prefetchConfiguration({
4961
warmAndPrefetchChrome: true,
5062
connectionTimeoutSeconds: 5,
51-
...configs.identityserver,
63+
...configs.auth0,
5264
});
5365
}, []);
5466

@@ -64,28 +76,27 @@ const App = () => {
6476
setAuthState({
6577
hasLoggedInOnce: true,
6678
provider: provider,
67-
...newAuthState
79+
...newAuthState,
6880
});
6981
} catch (error) {
7082
Alert.alert('Failed to log in', error.message);
7183
}
7284
},
73-
[authState]
85+
[authState],
7486
);
7587

7688
const handleRefresh = useCallback(async () => {
7789
try {
7890
const config = configs[authState.provider];
7991
const newAuthState = await refresh(config, {
80-
refreshToken: authState.refreshToken
92+
refreshToken: authState.refreshToken,
8193
});
8294

8395
setAuthState(current => ({
8496
...current,
8597
...newAuthState,
86-
refreshToken: newAuthState.refreshToken || current.refreshToken
87-
}))
88-
98+
refreshToken: newAuthState.refreshToken || current.refreshToken,
99+
}));
89100
} catch (error) {
90101
Alert.alert('Failed to refresh token', error.message);
91102
}
@@ -96,14 +107,14 @@ const App = () => {
96107
const config = configs[authState.provider];
97108
await revoke(config, {
98109
tokenToRevoke: authState.accessToken,
99-
sendClientId: true
110+
sendClientId: true,
100111
});
101112

102113
setAuthState({
103114
provider: '',
104115
accessToken: '',
105116
accessTokenExpirationDate: '',
106-
refreshToken: ''
117+
refreshToken: '',
107118
});
108119
} catch (error) {
109120
Alert.alert('Failed to revoke token', error.message);
@@ -122,7 +133,7 @@ const App = () => {
122133

123134
return (
124135
<Page>
125-
{!!authState.accessToken ? (
136+
{authState.accessToken ? (
126137
<Form>
127138
<FormLabel>accessToken</FormLabel>
128139
<FormValue>{authState.accessToken}</FormValue>
@@ -134,7 +145,9 @@ const App = () => {
134145
<FormValue>{authState.scopes.join(', ')}</FormValue>
135146
</Form>
136147
) : (
137-
<Heading>{authState.hasLoggedInOnce ? 'Goodbye.' : 'Hello, stranger.'}</Heading>
148+
<Heading>
149+
{authState.hasLoggedInOnce ? 'Goodbye.' : 'Hello, stranger.'}
150+
</Heading>
138151
)}
139152

140153
<ButtonContainer>
@@ -152,7 +165,7 @@ const App = () => {
152165
/>
153166
</>
154167
) : null}
155-
{!!authState.refreshToken ? (
168+
{authState.refreshToken ? (
156169
<Button onPress={handleRefresh} text="Refresh" color="#24C2CB" />
157170
) : null}
158171
{showRevoke ? (
@@ -161,6 +174,6 @@ const App = () => {
161174
</ButtonContainer>
162175
</Page>
163176
);
164-
}
177+
};
165178

166-
export default App;
179+
export default App;

Example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
android:label="@string/app_name"
1616
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
1717
android:launchMode="singleTask"
18-
android:windowSoftInputMode="adjustResize">
18+
android:windowSoftInputMode="adjustResize"
19+
android:exported="true">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122
<category android:name="android.intent.category.LAUNCHER" />

Example/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ buildscript {
44
ext {
55
buildToolsVersion = "29.0.2"
66
minSdkVersion = 16
7-
compileSdkVersion = 29
8-
targetSdkVersion = 29
7+
compileSdkVersion = 31
8+
targetSdkVersion = 31
99
}
1010
repositories {
1111
google()

Example/babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
const path = require('path');
2+
const pak = require('../package.json');
3+
14
module.exports = {
25
presets: ['module:metro-react-native-babel-preset'],
6+
plugins: [
7+
[
8+
'module-resolver',
9+
{
10+
extensions: ['.tsx', '.ts', '.js', '.json'],
11+
alias: {
12+
[pak.name]: path.join(__dirname, '..', pak.main),
13+
},
14+
},
15+
],
16+
],
317
};

Example/metro.config.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,32 @@
44
*
55
* @format
66
*/
7+
const path = require('path');
8+
9+
// As the example project uses `link:../` for react-native-owl, which creates a symlink, we need to manually map the project so it is properly used my Metro.
10+
// This will not be required by other projects using react-native-owl installed from a package repository.
11+
12+
const extraNodeModules = {
13+
'react-native-app-auth': path.resolve(path.join(__dirname, '..')),
14+
};
15+
const watchFolders = [path.resolve(path.join(__dirname, '..'))];
716

817
module.exports = {
918
transformer: {
1019
getTransformOptions: async () => ({
1120
transform: {
1221
experimentalImportSupport: false,
13-
inlineRequires: false,
22+
inlineRequires: true,
1423
},
1524
}),
1625
},
26+
resolver: {
27+
extraNodeModules: new Proxy(extraNodeModules, {
28+
get: (target, name) =>
29+
name in target
30+
? target[name]
31+
: path.join(process.cwd(), `node_modules/${name}`),
32+
}),
33+
},
34+
watchFolders,
1735
};

Example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"dependencies": {
1313
"react": "16.13.1",
1414
"react-native": "0.63.2",
15-
"react-native-app-auth": "FormidableLabs/react-native-app-auth#main"
15+
"react-native-app-auth": "link:../"
1616
},
1717
"devDependencies": {
1818
"@babel/core": "^7.8.4",
1919
"@babel/runtime": "^7.8.4",
2020
"@react-native-community/eslint-config": "^1.1.0",
2121
"babel-jest": "^25.1.0",
22+
"babel-plugin-module-resolver": "^4.1.0",
2223
"eslint": "^6.5.1",
2324
"jest": "^25.1.0",
2425
"metro-react-native-babel-preset": "^0.59.0",

Example/react-native.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
dependencies: {
5+
'react-native-app-auth': {
6+
root: path.join(__dirname, '..'),
7+
},
8+
},
9+
};

0 commit comments

Comments
 (0)