@veliseev93/clerk-react-native 0.0.1-dev.0
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 +133 -0
- package/dist/index.d.mts +653 -0
- package/dist/index.d.ts +653 -0
- package/dist/index.js +648 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +611 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ronas IT
|
|
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,133 @@
|
|
|
1
|
+
# @veliseev93/clerk-react-native
|
|
2
|
+
|
|
3
|
+
> Temporary npm scope for pre-release testing. Production package: `@ronas-it/clerk-react-native`.
|
|
4
|
+
|
|
5
|
+
Hooks and helpers for user authentication with [Clerk Expo SDK](https://clerk.com/docs/references/expo/overview).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @veliseev93/clerk-react-native @clerk/clerk-expo @clerk/types expo-web-browser expo-auth-session
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react`, `react-native`, and your Clerk/Expo versions should match what `@clerk/clerk-expo` expects for your Expo SDK.
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
### `useClerkResources`
|
|
18
|
+
|
|
19
|
+
Hook, that provides access to essential Clerk methods and objects.
|
|
20
|
+
|
|
21
|
+
Returned object:
|
|
22
|
+
|
|
23
|
+
- `signUp` — [SignUp](https://clerk.com/docs/references/javascript/sign-up)
|
|
24
|
+
- `signIn` — [SignIn](https://clerk.com/docs/references/javascript/sign-in)
|
|
25
|
+
- `setActive` — sets the active session
|
|
26
|
+
- `signOut` — signs out the current user
|
|
27
|
+
|
|
28
|
+
### `useAuthWithIdentifier`
|
|
29
|
+
|
|
30
|
+
Hook, that provides functionality to handle user sign-up and sign-in processes using an identifier such as an email, phone number, or username. It supports both OTP (One Time Password) and password-based authentication methods.
|
|
31
|
+
|
|
32
|
+
Parameters:
|
|
33
|
+
|
|
34
|
+
- `method`: type of identifier (`'emailAddress'`, `'phoneNumber'`, `'username'`)
|
|
35
|
+
- `verifyBy`: `'otp'` or `'password'`
|
|
36
|
+
|
|
37
|
+
Returned object:
|
|
38
|
+
|
|
39
|
+
- `startSignUp`, `startSignIn`, `startAuthorization`, `isLoading`
|
|
40
|
+
- For email/phone + OTP: `verifyCode`, `isVerifying` (`verifyCode` requires `code`, `isSignUp`, optional `tokenTemplate`)
|
|
41
|
+
|
|
42
|
+
**Example:**
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import React, { useState } from 'react';
|
|
46
|
+
import { View, TextInput, Button } from 'react-native';
|
|
47
|
+
import { useAuthWithIdentifier } from '@veliseev93/clerk-react-native';
|
|
48
|
+
|
|
49
|
+
export const AuthWithIdentifierComponent = () => {
|
|
50
|
+
const [identifier, setIdentifier] = useState('');
|
|
51
|
+
const [verificationCode, setVerificationCode] = useState('');
|
|
52
|
+
const { startSignUp, verifyCode, isLoading, isVerifying } = useAuthWithIdentifier('emailAddress', 'otp');
|
|
53
|
+
|
|
54
|
+
const handleSignUp = async () => {
|
|
55
|
+
await startSignUp({ identifier });
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleVerifyCode = async () => {
|
|
59
|
+
const result = await verifyCode({ code: verificationCode, isSignUp: true });
|
|
60
|
+
console.log(result.sessionToken);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View>
|
|
65
|
+
<TextInput
|
|
66
|
+
placeholder="Enter your email"
|
|
67
|
+
value={identifier}
|
|
68
|
+
onChangeText={setIdentifier}
|
|
69
|
+
keyboardType="email-address"
|
|
70
|
+
/>
|
|
71
|
+
<TextInput
|
|
72
|
+
placeholder="Enter verification code"
|
|
73
|
+
value={verificationCode}
|
|
74
|
+
onChangeText={setVerificationCode}
|
|
75
|
+
/>
|
|
76
|
+
<Button onPress={handleSignUp} title="Sign Up" disabled={isLoading || isVerifying} />
|
|
77
|
+
<Button onPress={handleVerifyCode} title="Verify code" disabled={isLoading || isVerifying} />
|
|
78
|
+
</View>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `useAuthWithSSO`
|
|
84
|
+
|
|
85
|
+
Hook for [SSO](https://clerk.com/docs/references/expo/use-sso) flows.
|
|
86
|
+
|
|
87
|
+
- `startSSOFlow` — `strategy`, `redirectUrl`, optional `tokenTemplate`
|
|
88
|
+
- `isLoading`
|
|
89
|
+
|
|
90
|
+
### `useAuthWithTicket`
|
|
91
|
+
|
|
92
|
+
Ticket-based auth (token from Backend API).
|
|
93
|
+
|
|
94
|
+
- `startAuthorization` — `ticket`, optional `tokenTemplate`
|
|
95
|
+
- `isLoading`
|
|
96
|
+
|
|
97
|
+
### `useGetSessionToken`
|
|
98
|
+
|
|
99
|
+
- `getSessionToken` — optional [token template](https://clerk.com/docs/backend-requests/jwt-templates)
|
|
100
|
+
|
|
101
|
+
### `useAddIdentifier`
|
|
102
|
+
|
|
103
|
+
Add email or phone identifiers and verify with codes.
|
|
104
|
+
|
|
105
|
+
- `createIdentifier`, `verifyCode`, `isCreating`, `isVerifying`
|
|
106
|
+
|
|
107
|
+
### `useUpdateIdentifier`
|
|
108
|
+
|
|
109
|
+
Update primary email or phone: add and verify new identifier, then set primary and remove old.
|
|
110
|
+
|
|
111
|
+
- `createIdentifier`, `verifyCode`, `isCreating`, `isVerifying`, `isUpdating`
|
|
112
|
+
|
|
113
|
+
### `useOtpVerification`
|
|
114
|
+
|
|
115
|
+
Lower-level OTP send/verify for sign-in and sign-up.
|
|
116
|
+
|
|
117
|
+
- `sendOtpCode`, `verifyCode`, `isVerifying`
|
|
118
|
+
|
|
119
|
+
### `useResetPassword`
|
|
120
|
+
|
|
121
|
+
Password reset via email or phone OTP.
|
|
122
|
+
|
|
123
|
+
- `startResetPassword`, `verifyCode`, `resetPassword`, `isCodeSending`, `isResetting`, `isVerifying`
|
|
124
|
+
|
|
125
|
+
### `useChangePassword`
|
|
126
|
+
|
|
127
|
+
Update the signed-in user's password (`currentPassword`, `newPassword`).
|
|
128
|
+
|
|
129
|
+
- `updatePassword`, `isPasswordUpdating`
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|