Skip to content

Commit 5f67689

Browse files
authored
refactor(rn): mark all native modules as peer dependency (#17)
* refactor(rn): mark all native modules as peer dependency mask all native modules as peer dependency * fix: add commit lint configs add commit lint configs * feat: update readme update readme * chore: update the readme content update the read me content * fix: content update content update * chore: update code syntax update code syntax
1 parent e8e6097 commit 5f67689

File tree

10 files changed

+644
-38
lines changed

10 files changed

+644
-38
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ node_modules/
88
dist/
99
web-build/
1010
lib/
11+
android
12+
ios
1113

1214
# Native
1315
*.orig.*

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no-install commitlint --edit ""

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Keep concurrency 1 to avoid lint-staged issue
2+
# Which may cause ALL your work LOST WITHOUT STASH
3+
FORCE_COLOR=1 pnpm -r --workspace-concurrency 1 --filter "[HEAD]" precommit

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,93 @@ The monorepo for Logto React Native (Expo) SDK and sample.
1717
- [@logto/rn](./packages/rn) - Logto React Native SDK
1818
- [@logto/rn-sample](./packages/rn-sample) - Sample app using Logto React Native SDK
1919

20+
## Installation
21+
22+
```bash
23+
npm install @logto/rn --save
24+
npm install expo-crypto expo-secure-store expo-web-browser @react-native-async-storage/async-storage
25+
```
26+
27+
The `@logto/rn` package is the SDK for Logto. The remaining packages are its peer dependencies. They couldn't be listed as direct dependencies because the Expo CLI requires that all dependencies for native modules be installed directly within the root project's package.json.
28+
29+
You could also use other package managers such as `yarn` or `pnpm`.
30+
31+
## Configuration
32+
33+
To make the redirect URI deep link work, you need to configure the `scheme` in the `app.json` file.
34+
35+
e.g. In the `@logto/rn-sample` we use `io.logto://callback` as the callback URL.
36+
37+
```json
38+
{
39+
"expo": {
40+
"scheme": "io.logto"
41+
}
42+
}
43+
```
44+
45+
## Integration
46+
47+
```tsx
48+
import { LogtoProvider, useLogto } from "@logto/rn";
49+
50+
const App = () => {
51+
const { signIn, signOut, isAuthenticated } = useLogto();
52+
53+
const logtoConfig = {
54+
appId: "YOUR_APP",
55+
endpoint: "YOUR_LOGTO_ENDPOINT",
56+
};
57+
58+
return (
59+
<LogtoProvider config={logtoConfig}>
60+
{isAuthenticated ? (
61+
<Button title="Sign Out" onPress={signOut} />
62+
) : (
63+
<Button title="Sign In" onPress={async () => signIn(redirectUri)} />
64+
)}
65+
</LogtoProvider>
66+
);
67+
};
68+
```
69+
70+
## Run the sample app
71+
72+
### Replace the `appId` and `endpoint` in `App.tsx` with your own Logto settings.
73+
74+
```tsx
75+
const endpoint = "YOUR_LOGTO_ENDPOINT";
76+
const appId = "YOUR_APP_ID";
77+
```
78+
79+
### Run using Expo Go
80+
81+
> [!Caution]
82+
> This SDK is not compatible with "Expo Go" sandbox on Android.
83+
> Under the hood, this SDK uses `ExpoAuthSession` to handle the user authentication flow. Native deep linking is not supported in "Expo Go". For more details please refer to [deep-linking](https://docs.expo.dev/guides/deep-linking/)
84+
> Use [development-build](https://docs.expo.dev/develop/development-builds/introduction/) to test this SDK on Android.
85+
86+
Under the path `packages/rn-sample` run the following command.
87+
88+
```bash
89+
pnpm dev:ios
90+
```
91+
92+
### Build and run native package
93+
94+
Under the path `packages/rn-sample` run the following command.
95+
96+
```bash
97+
# Run expo
98+
pnpm expo run
99+
100+
# Directly run on android device
101+
# pnpm android
102+
103+
# Directly run on ios device
104+
# pnpm ios
105+
```
106+
20107
## Resources
21108

22109
- [📖 Logto docs](https://docs.logto.io/?utm_source=github&utm_medium=repo_logto)

commitlint.config.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { rules } = require('@commitlint/config-conventional');
2+
3+
/** @type {import('@commitlint/types').UserConfig} **/
4+
module.exports = {
5+
extends: ['@commitlint/config-conventional'],
6+
rules: {
7+
'type-enum': [2, 'always', [...rules['type-enum'][2], 'release']],
8+
},
9+
};

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"license": "UNLICENSED",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"devDependencies": {
10+
"@commitlint/cli": "^18.6.1",
11+
"@commitlint/config-conventional": "^18.6.1",
12+
"@commitlint/types": "^18.6.1",
13+
"husky": "^9.0.11"
814
}
915
}

packages/rn-sample/app.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
"resizeMode": "contain",
1212
"backgroundColor": "#ffffff"
1313
},
14-
"assetBundlePatterns": [
15-
"**/*"
16-
],
14+
"assetBundlePatterns": ["**/*"],
1715
"ios": {
1816
"supportsTablet": true
1917
},
@@ -25,6 +23,7 @@
2523
},
2624
"web": {
2725
"favicon": "./assets/favicon.png"
28-
}
26+
},
27+
"scheme": "io.logto"
2928
}
3029
}

packages/rn-sample/package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
"version": "0.1.0",
55
"main": "index.js",
66
"scripts": {
7-
"start": "expo start",
8-
"android": "expo start --android",
9-
"ios": "expo start --ios",
10-
"web": "expo start --web"
7+
"dev": "expo start",
8+
"dev:android": "expo start --android",
9+
"dev:ios": "expo start --ios",
10+
"android": "expo run:android",
11+
"ios": "expo run:ios"
1112
},
1213
"dependencies": {
1314
"@logto/rn": "workspace:^",
15+
"@react-native-async-storage/async-storage": "^1.22.0",
1416
"expo": "~50.0.6",
17+
"expo-crypto": "^12.8.1",
18+
"expo-secure-store": "^12.8.1",
1519
"expo-status-bar": "~1.11.1",
20+
"expo-web-browser": "^12.8.2",
1621
"react": "18.2.0",
1722
"react-native": "0.73.4"
1823
},

packages/rn/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@
5555
"dependencies": {
5656
"@logto/client": "3.0.0-alpha.2",
5757
"@logto/js": "4.0.0-alpha.2",
58-
"@react-native-async-storage/async-storage": "^1.22.0",
5958
"crypto-es": "^2.1.0",
59+
"js-base64": "^3.7.6"
60+
},
61+
"peerDependencies": {
62+
"@react-native-async-storage/async-storage": "^1.22.0",
6063
"expo-crypto": "^12.8.0",
6164
"expo-secure-store": "^12.8.1",
62-
"expo-web-browser": "^12.8.2",
63-
"js-base64": "^3.7.6"
65+
"expo-web-browser": "^12.8.2"
6466
}
6567
}

0 commit comments

Comments
 (0)