@authowl/react-native 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +225 -0
- package/THIRD_PARTY_NOTICES.md +8 -0
- package/dist/index.cjs +1193 -0
- package/dist/index.d.cts +654 -0
- package/dist/index.d.ts +654 -0
- package/dist/index.js +1160 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AuthOwl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @authowl/react-native
|
|
2
|
+
|
|
3
|
+
**[Complete SDK guide](https://authowl.dev/docs/sdks/react-native)** ·
|
|
4
|
+
**[Expo adapter](https://authowl.dev/docs/sdks/expo)**
|
|
5
|
+
|
|
6
|
+
React Native provider, hooks, and secure session storage for
|
|
7
|
+
[AuthOwl](https://authowl.dev).
|
|
8
|
+
|
|
9
|
+
Using **Expo**? Install [`@authowl/expo`](../auth-expo) instead - it re-exports
|
|
10
|
+
everything here and supplies the platform adapters for you.
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @authowl/react-native react-native-keychain
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Why this package exists
|
|
17
|
+
|
|
18
|
+
The browser SDK leans on things a phone does not have: a cookie jar, a
|
|
19
|
+
`BroadcastChannel`, and `window.location` redirects. This package supplies native
|
|
20
|
+
an explicit session jar and leaves the rest to `@authowl/core/native`:
|
|
21
|
+
|
|
22
|
+
1. **A session that survives an app restart.** React Native's `fetch` cookie
|
|
23
|
+
behaviour differs between iOS and Android, is invisible to JS, and does not
|
|
24
|
+
reliably persist. So the SDK keeps the one cookie it cares about itself, in
|
|
25
|
+
the OS keychain, and replays it on every request. The server sees exactly what
|
|
26
|
+
a browser would send - no native-only server mode.
|
|
27
|
+
|
|
28
|
+
The native client deliberately excludes redirect OAuth and enterprise SSO,
|
|
29
|
+
which depend on browser state unavailable to a React Native fetch client.
|
|
30
|
+
Passkeys are available when the app supplies its platform ceremony adapter.
|
|
31
|
+
|
|
32
|
+
## Setup
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { AuthOwlProvider } from '@authowl/react-native';
|
|
36
|
+
import * as Keychain from 'react-native-keychain';
|
|
37
|
+
|
|
38
|
+
const storage = {
|
|
39
|
+
async getItem(key) {
|
|
40
|
+
const entry = await Keychain.getGenericPassword({ service: key });
|
|
41
|
+
return entry ? entry.password : null;
|
|
42
|
+
},
|
|
43
|
+
setItem: (key, value) =>
|
|
44
|
+
Keychain.setGenericPassword(key, value, { service: key }).then(() => undefined),
|
|
45
|
+
removeItem: (key) => Keychain.resetGenericPassword({ service: key }).then(() => undefined),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default function Root() {
|
|
49
|
+
return (
|
|
50
|
+
<AuthOwlProvider
|
|
51
|
+
publishableKey={PUBLISHABLE_KEY}
|
|
52
|
+
apiUrl="https://api.authowl.dev"
|
|
53
|
+
storage={storage}
|
|
54
|
+
>
|
|
55
|
+
<App />
|
|
56
|
+
</AuthOwlProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Use the OS keychain, **not** AsyncStorage. The session cookie is a bearer
|
|
62
|
+
credential - anything holding it *is* the signed-in user until it expires - and
|
|
63
|
+
AsyncStorage is unencrypted files readable by anything in the app sandbox.
|
|
64
|
+
|
|
65
|
+
There is deliberately no default storage: silently falling back to memory would
|
|
66
|
+
make sign-in appear to work and then drop the session on the next launch.
|
|
67
|
+
|
|
68
|
+
## Components
|
|
69
|
+
|
|
70
|
+
Drop-in screens built from React Native primitives, using the same localization
|
|
71
|
+
catalogs as the web components (`@authowl/core/i18n`) so the wording never
|
|
72
|
+
drifts between platforms.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { EmailOtpForm, SignIn, SignUp, SocialButtons } from '@authowl/react-native';
|
|
76
|
+
|
|
77
|
+
<SignIn
|
|
78
|
+
onSignedIn={() => router.replace('/home')}
|
|
79
|
+
onSecondFactorRequired={() => router.replace('/mfa')}
|
|
80
|
+
/>
|
|
81
|
+
<SignUp onSignedUp={({ sessionCreated }) =>
|
|
82
|
+
router.replace(sessionCreated ? '/home' : '/check-your-email')} />
|
|
83
|
+
<EmailOtpForm onSignedIn={() => router.replace('/home')} />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`<SignIn />` reports success **only once a session exists**. A two-factor
|
|
87
|
+
challenge is neither a failure nor a session, so it calls
|
|
88
|
+
`onSecondFactorRequired` and leaves the form intact for the app to navigate to
|
|
89
|
+
its challenge screen.
|
|
90
|
+
|
|
91
|
+
`<SignUp />` reports whether a session was created. Projects that require email
|
|
92
|
+
verification return none, and "check your email" is a different screen from
|
|
93
|
+
"you're in".
|
|
94
|
+
|
|
95
|
+
The provider loads the project's public capabilities once. Built-in screens
|
|
96
|
+
hide disabled methods, enforce the configured password length, collect required
|
|
97
|
+
legal consent, and send the accepted consent version automatically.
|
|
98
|
+
|
|
99
|
+
Pass `locale="ar"` to `<AuthOwlProvider>` to render Arabic. It is not
|
|
100
|
+
auto-detected from the device: a phone set to Arabic does not mean the app is
|
|
101
|
+
localized, and switching only the auth screens is worse than defaulting.
|
|
102
|
+
|
|
103
|
+
Theming is a small token set, not a cascade:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { darkTheme } from '@authowl/react-native';
|
|
107
|
+
|
|
108
|
+
<SignIn theme={darkTheme} />
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Both built-in themes use AuthOwl gold (`#F5B84C`) for primary controls by
|
|
112
|
+
default. Pass a custom `AuthOwlTheme` to a component only when the app should
|
|
113
|
+
replace that brand color; `link` can optionally provide a contrast-safe inline
|
|
114
|
+
link color distinct from the filled-control `accent`.
|
|
115
|
+
|
|
116
|
+
Want a different look entirely? Compose the hooks instead of fighting the
|
|
117
|
+
components — that is what they are for.
|
|
118
|
+
|
|
119
|
+
### Organizations
|
|
120
|
+
|
|
121
|
+
```tsx
|
|
122
|
+
<OrganizationSwitcher onSwitched={(org) => refetch(org)} />
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Reads the active organization from the session rather than tracking it locally,
|
|
126
|
+
because switching re-mints the session claim server-side. The "personal account"
|
|
127
|
+
row is off by default — many apps require an organization context to function.
|
|
128
|
+
|
|
129
|
+
### Passkeys
|
|
130
|
+
|
|
131
|
+
React Native has no `navigator.credentials`, but both platforms have passkey
|
|
132
|
+
APIs. Supply the ceremony from a native library and the SDK keeps the protocol:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { Passkey } from 'react-native-passkey';
|
|
136
|
+
import { AuthOwlProvider, createNativePasskeys } from '@authowl/react-native';
|
|
137
|
+
|
|
138
|
+
const passkeys = createNativePasskeys({
|
|
139
|
+
register: (options) => Passkey.create(options as never),
|
|
140
|
+
authenticate: (options) => Passkey.get(options as never),
|
|
141
|
+
// Users cancel far more often than anything breaks, so map it.
|
|
142
|
+
errorCode: (error) =>
|
|
143
|
+
(error as { error?: string })?.error === 'UserCancelled'
|
|
144
|
+
? 'REGISTRATION_CANCELLED'
|
|
145
|
+
: undefined,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
<AuthOwlProvider {...config} passkeys={passkeys}>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Then:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
<PasskeyEnrollment name="iPhone" onEnrolled={next} onSkip={next} />
|
|
155
|
+
<PasskeySignInButton onSignedIn={() => router.replace('/home')} />
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Without a `passkeys` adapter these components render nothing, and the passkey
|
|
159
|
+
methods are absent from the client's type entirely** — so an app cannot call a
|
|
160
|
+
prompt the platform could never show. That also means it is safe to drop
|
|
161
|
+
`<PasskeyEnrollment />` into a post-sign-up flow that runs on projects with
|
|
162
|
+
passkeys disabled.
|
|
163
|
+
|
|
164
|
+
Both need associated-domain configuration (`webcredentials:` on iOS, Digital
|
|
165
|
+
Asset Links on Android) that the SDK cannot do on your behalf.
|
|
166
|
+
|
|
167
|
+
### Social buttons
|
|
168
|
+
|
|
169
|
+
`<SocialButtons />` takes the provider SDKs from your app, because they differ
|
|
170
|
+
per provider and platform and bundling one would force it on every consumer:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
<SocialButtons
|
|
174
|
+
providers={[{
|
|
175
|
+
id: 'google',
|
|
176
|
+
label: 'Google',
|
|
177
|
+
// Return null when the user cancels - that is not an error.
|
|
178
|
+
getIdToken: async () => {
|
|
179
|
+
const result = await GoogleSignin.signIn();
|
|
180
|
+
return result.idToken ? { token: result.idToken } : null;
|
|
181
|
+
},
|
|
182
|
+
}]}
|
|
183
|
+
onSignedIn={() => router.replace('/home')}
|
|
184
|
+
/>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Hooks
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
const { isLoaded, isSignedIn, user, signOut, has } = useAuth();
|
|
191
|
+
|
|
192
|
+
if (!isLoaded) return <Splash />;
|
|
193
|
+
if (!isSignedIn) return <SignInScreen />;
|
|
194
|
+
|
|
195
|
+
// Advisory only - for hiding UI the user cannot use. The real boundary is
|
|
196
|
+
// server-side, over a verified token.
|
|
197
|
+
if (has({ permission: 'org:billing:read' })) return <Billing />;
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- `useAuth()` - the primary hook: user, session, `signOut`, `has`, `hasPermission`
|
|
201
|
+
- `useUser()` - the signed-in user, or `null`
|
|
202
|
+
- `useSession()` - raw session state (`isPending`, `error`, `refetch`)
|
|
203
|
+
- `useAuthOwlClient()` - native-safe sign-in, account, organization, and passkey management actions
|
|
204
|
+
- `useSocialSignIn()` - exchanges a provider-issued ID token for an AuthOwl session
|
|
205
|
+
|
|
206
|
+
## Social sign-in
|
|
207
|
+
|
|
208
|
+
Obtain an ID token with the provider's native SDK, then exchange it through the
|
|
209
|
+
hook. The request and session response use the same secure cookie jar.
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
const signInWith = useSocialSignIn();
|
|
213
|
+
const result = await signInWith({
|
|
214
|
+
provider: 'google',
|
|
215
|
+
idToken: { token: googleResult.idToken },
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Redirect OAuth is not exposed because the AuthOwl fetch cookie jar and a system
|
|
220
|
+
browser do not share the OAuth state cookie. A deep link alone cannot establish
|
|
221
|
+
the app session safely.
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
`@authowl/react-native` bundles third-party components into its published `dist/`. Each
|
|
4
|
+
is redistributed under its own license, with the required copyright and
|
|
5
|
+
permission notices reproduced in full below, grouped by copyright holder. This
|
|
6
|
+
file is generated by `scripts/gen-notices.mjs`; do not edit by hand.
|
|
7
|
+
|
|
8
|
+
No third-party code is bundled into this package.
|