@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/dist/index.d.mts
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { ClerkAPIError, SignInResource, SignInStatus, SignUpResource, SignUpCreateParams, OAuthStrategy, UserResource, PhoneNumberResource, EmailAddressResource, SetActive, SignOut, UpdateUserPasswordParams } from '@clerk/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enum containing common Clerk API error codes
|
|
5
|
+
*/
|
|
6
|
+
declare enum ClerkApiError {
|
|
7
|
+
/** Error when a session already exists */
|
|
8
|
+
SESSION_EXISTS = "session_exists",
|
|
9
|
+
/** Error when an identifier (email/phone) already exists */
|
|
10
|
+
FORM_IDENTIFIER_EXIST = "form_identifier_exists",
|
|
11
|
+
/** Error when the verification code is incorrect */
|
|
12
|
+
FORM_CODE_INCORRECT = "form_code_incorrect"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type BaseSuccessReturn = {
|
|
16
|
+
isSuccess: true;
|
|
17
|
+
error?: never;
|
|
18
|
+
};
|
|
19
|
+
type BaseFailureReturn = {
|
|
20
|
+
isSuccess?: false;
|
|
21
|
+
error: ClerkAPIError | unknown;
|
|
22
|
+
};
|
|
23
|
+
type WithTokenSuccessReturn = BaseSuccessReturn & {
|
|
24
|
+
sessionToken: string;
|
|
25
|
+
};
|
|
26
|
+
type WithTokenFailureReturn = BaseFailureReturn & {
|
|
27
|
+
sessionToken?: null;
|
|
28
|
+
};
|
|
29
|
+
type WithSignInReturn = {
|
|
30
|
+
/** Provides access to SignIn object: https://clerk.com/docs/references/javascript/sign-in */
|
|
31
|
+
signIn?: SignInResource;
|
|
32
|
+
/** The current status of the sign-in. */
|
|
33
|
+
status?: SignInStatus;
|
|
34
|
+
};
|
|
35
|
+
type WithSignUpReturn = {
|
|
36
|
+
/** Provides access to SignUp object: https://clerk.com/docs/references/javascript/sign-up */
|
|
37
|
+
signUp?: SignUpResource;
|
|
38
|
+
};
|
|
39
|
+
type WithClerkReturn = WithSignInReturn & WithSignUpReturn;
|
|
40
|
+
type StartSignUpReturn = (BaseSuccessReturn | BaseFailureReturn) & WithSignUpReturn;
|
|
41
|
+
type StartSignInReturn = (BaseSuccessReturn | BaseFailureReturn) & WithSignInReturn;
|
|
42
|
+
type StartAuthorizationReturn = (BaseSuccessReturn | BaseFailureReturn) & WithClerkReturn & {
|
|
43
|
+
isSignUp?: boolean;
|
|
44
|
+
};
|
|
45
|
+
type AuthorizationFinishedReturn = (WithTokenSuccessReturn | WithTokenFailureReturn) & WithClerkReturn;
|
|
46
|
+
/** Type for OTP methods (email or phone) */
|
|
47
|
+
type OtpMethod = 'emailAddress' | 'phoneNumber';
|
|
48
|
+
/** Type for OTP strategies (email code or phone code) */
|
|
49
|
+
type OtpStrategy = 'email_code' | 'phone_code';
|
|
50
|
+
/** Type for extra params during SignUp process */
|
|
51
|
+
type SignUpParams = Pick<SignUpCreateParams, 'firstName' | 'lastName' | 'locale' | 'unsafeMetadata' | 'username'>;
|
|
52
|
+
type UseClerkResourcesReturn = WithClerkReturn & {
|
|
53
|
+
/** A function that sets the active session */
|
|
54
|
+
setActive: SetActive;
|
|
55
|
+
/** A function that signs out the current user */
|
|
56
|
+
signOut: SignOut;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the session token for the currently authenticated user.
|
|
60
|
+
*
|
|
61
|
+
* @param params - Optional parameters for retrieving the session token.
|
|
62
|
+
* @param params.tokenTemplate - (Optional) Name of the token template to use.
|
|
63
|
+
*
|
|
64
|
+
* @returns A Promise resolving to:
|
|
65
|
+
* - { isSuccess: true, sessionToken: string } on success
|
|
66
|
+
* - { isSuccess: false, sessionToken: null, error } on failure
|
|
67
|
+
*/
|
|
68
|
+
type GetSessionTokenFn = (params: {
|
|
69
|
+
tokenTemplate?: string;
|
|
70
|
+
}) => Promise<GetSessionTokenReturn>;
|
|
71
|
+
interface UseGetSessionTokenReturn {
|
|
72
|
+
/** Function to retrieve the session token */
|
|
73
|
+
getSessionToken: GetSessionTokenFn;
|
|
74
|
+
}
|
|
75
|
+
type GetSessionTokenReturn = WithTokenSuccessReturn | WithTokenFailureReturn;
|
|
76
|
+
type StartAuthorizationWithTicketReturn = (WithTokenSuccessReturn | WithTokenFailureReturn) & WithSignInReturn;
|
|
77
|
+
interface UseAuthWithTicketReturn {
|
|
78
|
+
/**
|
|
79
|
+
* Initiates authentication using a one-time ticket issued by the backend.
|
|
80
|
+
*
|
|
81
|
+
* @param params - Parameters required to start the ticket-based authentication flow.
|
|
82
|
+
* @param params.ticket - A valid ticket string issued by Clerk or your backend.
|
|
83
|
+
* @param params.tokenTemplate - (Optional) The name of a token template to use when retrieving the session token.
|
|
84
|
+
*
|
|
85
|
+
* @returns A Promise that resolves to a `StartAuthorizationWithTicketReturn` object, which can be either:
|
|
86
|
+
*
|
|
87
|
+
* On success:
|
|
88
|
+
* - `isSuccess: true`
|
|
89
|
+
* - `sessionToken: string` — A valid session token string.
|
|
90
|
+
* - `signIn?: SignInResource` — (Optional) SignIn object, present if the user needs to complete additional steps.
|
|
91
|
+
*
|
|
92
|
+
* On failure:
|
|
93
|
+
* - `isSuccess: false` or undefined
|
|
94
|
+
* - `sessionToken: null`
|
|
95
|
+
* - `error: ClerkAPIError | unknown` — Details about the error occurred.
|
|
96
|
+
* - `signIn?: SignInResource` — (Optional) SignIn object if available.
|
|
97
|
+
*/
|
|
98
|
+
startAuthorization: (params: {
|
|
99
|
+
ticket: string;
|
|
100
|
+
tokenTemplate?: string;
|
|
101
|
+
}) => Promise<StartAuthorizationWithTicketReturn>;
|
|
102
|
+
/** Indicates whether the authentication process with the ticket is currently in progress. `true` or `false` */
|
|
103
|
+
isLoading: boolean;
|
|
104
|
+
}
|
|
105
|
+
/** Parameters for SSO flow */
|
|
106
|
+
interface StartSSOArgs {
|
|
107
|
+
/**
|
|
108
|
+
* The OAuth strategy to use (e.g., 'oauth_google', 'oauth_facebook', etc.).
|
|
109
|
+
* See Clerk's documentation for a full list of supported strategies: https://clerk.com/docs/references/expo/use-sso
|
|
110
|
+
*/
|
|
111
|
+
strategy: OAuthStrategy;
|
|
112
|
+
/** Optional URL to redirect the user to after successful authentication. */
|
|
113
|
+
redirectUrl?: string;
|
|
114
|
+
/** Optional name of a token template to use for customizing the returned session token. */
|
|
115
|
+
tokenTemplate?: string;
|
|
116
|
+
}
|
|
117
|
+
/** Return type for useAuthWithSSO hook */
|
|
118
|
+
interface UseAuthWithSSOReturn {
|
|
119
|
+
/**
|
|
120
|
+
* Initiates a Single Sign-On (SSO) authentication flow using the specified OAuth strategy.
|
|
121
|
+
*
|
|
122
|
+
* @param params - Parameters for initiating the SSO flow.
|
|
123
|
+
* @param params.strategy - The OAuth strategy to use (e.g., 'oauth_google', 'oauth_facebook').
|
|
124
|
+
* @param params.redirectUrl - (Optional) A URL to which the user will be redirected after the flow completes.
|
|
125
|
+
* @param params.tokenTemplate - (Optional) A token template to use when requesting a session token.
|
|
126
|
+
*
|
|
127
|
+
* @returns A Promise that resolves to an object indicating the result of the authorization:
|
|
128
|
+
* - `{ isSuccess: true, sessionToken: string, signIn?, signUp? }` on success
|
|
129
|
+
* - `{ isSuccess: false, sessionToken: null, error, signIn?, signUp? }` on failure
|
|
130
|
+
*
|
|
131
|
+
* `signIn` and `signUp` may be present depending on the outcome and stage of the flow.
|
|
132
|
+
*/
|
|
133
|
+
startSSOFlow: (params: StartSSOArgs) => Promise<AuthorizationFinishedReturn>;
|
|
134
|
+
/** Indicates whether the SSO authentication flow is currently in progress. `true` or `false` */
|
|
135
|
+
isLoading: boolean;
|
|
136
|
+
}
|
|
137
|
+
/** Provides functionality for sending and verifying OTP (one-time password) codes using email or phone. */
|
|
138
|
+
interface UseOtpVerificationReturn {
|
|
139
|
+
/**
|
|
140
|
+
* Sends a one-time password (OTP) code to the user's identifier (email or phone number),
|
|
141
|
+
* using the selected strategy.
|
|
142
|
+
*
|
|
143
|
+
* @param strategy - The delivery method for the OTP code.
|
|
144
|
+
* - `'email_code'` – send code via email
|
|
145
|
+
* - `'phone_code'` – send code via SMS
|
|
146
|
+
* @param isSignUp - Indicates whether the OTP flow is used for sign-up (true) or sign-in (false)
|
|
147
|
+
* @param isSecondFactor - (Optional) Indicates whether the OTP flow is used for a second factor verification (true) or not (false)
|
|
148
|
+
*
|
|
149
|
+
* @returns A Promise that resolves once the OTP has been successfully sent, or rejects if sending fails.
|
|
150
|
+
*/
|
|
151
|
+
sendOtpCode: (params: {
|
|
152
|
+
strategy: OtpStrategy;
|
|
153
|
+
isSignUp: boolean;
|
|
154
|
+
isSecondFactor?: boolean;
|
|
155
|
+
}) => Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Verifies the OTP code entered by the user.
|
|
158
|
+
*
|
|
159
|
+
* @param params - Parameters required to verify the code.
|
|
160
|
+
* @param params.code - The OTP code received by the user.
|
|
161
|
+
* @param params.strategy - The strategy used to send the code (`'email_code'` or `'phone_code'`).
|
|
162
|
+
* @param params.tokenTemplate - (Optional) The name of the token template to use when retrieving the session token.
|
|
163
|
+
* @param isSignUp - Indicates whether the OTP flow is used for sign-up (true) or sign-in (false)
|
|
164
|
+
* @param isSecondFactor - (Optional) Indicates whether the OTP flow is used for a second factor verification (true) or not (false)
|
|
165
|
+
*
|
|
166
|
+
* @returns A Promise that resolves to:
|
|
167
|
+
* - `{ isSuccess: true, sessionToken: string, signIn?, signUp? }` on success
|
|
168
|
+
* - `{ isSuccess: false, sessionToken: null, error, signIn?, signUp? }` on failure
|
|
169
|
+
*/
|
|
170
|
+
verifyCode: (params: {
|
|
171
|
+
code: string;
|
|
172
|
+
strategy: OtpStrategy;
|
|
173
|
+
isSignUp: boolean;
|
|
174
|
+
tokenTemplate?: string;
|
|
175
|
+
isSecondFactor?: boolean;
|
|
176
|
+
}) => Promise<AuthorizationFinishedReturn>;
|
|
177
|
+
/** Indicates whether the OTP verification process is currently in progress. `true` or `false` */
|
|
178
|
+
isVerifying: boolean;
|
|
179
|
+
}
|
|
180
|
+
type IdentifierType = 'email' | 'phone';
|
|
181
|
+
/**
|
|
182
|
+
* Return type for a hook that manages adding a new authentication identifier
|
|
183
|
+
* (such as an email address or phone number) to the currently signed-in user's account.
|
|
184
|
+
*/
|
|
185
|
+
interface UseAddIdentifierReturn {
|
|
186
|
+
/**
|
|
187
|
+
* Sends a request to create and link a new identifier (email or phone) to the current user.
|
|
188
|
+
*
|
|
189
|
+
* This triggers a verification flow (e.g., a code sent via email or SMS) and returns
|
|
190
|
+
* a result indicating success or failure. On success, the identifier is pending verification.
|
|
191
|
+
*
|
|
192
|
+
* @param params - Parameters for identifier creation.
|
|
193
|
+
* @param params.identifier - The new identifier to be added (e.g., email or phone number).
|
|
194
|
+
*
|
|
195
|
+
* @returns A Promise resolving to a result object:
|
|
196
|
+
* - On success: `BaseSuccessReturn` with optional `user`.
|
|
197
|
+
* - On failure: `BaseFailureReturn` with optional `user`.
|
|
198
|
+
*/
|
|
199
|
+
createIdentifier: (params: {
|
|
200
|
+
identifier: string;
|
|
201
|
+
}) => Promise<(BaseSuccessReturn | BaseFailureReturn) & {
|
|
202
|
+
user?: UserResource | null;
|
|
203
|
+
}>;
|
|
204
|
+
/**
|
|
205
|
+
* Verifies the code sent to the newly added identifier.
|
|
206
|
+
*
|
|
207
|
+
* @param params - Parameters for verification.
|
|
208
|
+
* @param params.code - The one-time code sent to the identifier.
|
|
209
|
+
*
|
|
210
|
+
* @returns A Promise resolving to a result object:
|
|
211
|
+
* - On success: `BaseSuccessReturn` with optional `user`.
|
|
212
|
+
* - On failure: `BaseFailureReturn` with optional `verifyAttempt` (email or phone resource) and `user`.
|
|
213
|
+
*/
|
|
214
|
+
verifyCode: (params: {
|
|
215
|
+
code: string;
|
|
216
|
+
identifier: string;
|
|
217
|
+
}) => Promise<(BaseSuccessReturn | (BaseFailureReturn & {
|
|
218
|
+
verifyAttempt?: PhoneNumberResource | EmailAddressResource;
|
|
219
|
+
})) & {
|
|
220
|
+
user?: UserResource | null;
|
|
221
|
+
}>;
|
|
222
|
+
/** Indicates whether an identifier is currently being added via `createIdentifier`. `true` or `false` */
|
|
223
|
+
isCreating: boolean;
|
|
224
|
+
/** Indicates whether a verification request is currently being processed via `verifyCode`. `true` or `false` */
|
|
225
|
+
isVerifying: boolean;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Return type for a hook that manages updating a new authentication identifier
|
|
229
|
+
* (such as an email address or phone number) to the currently signed-in user's account.
|
|
230
|
+
*/
|
|
231
|
+
interface UseUpdateIdentifierReturn extends Omit<UseAddIdentifierReturn, 'verifyCode'> {
|
|
232
|
+
/**
|
|
233
|
+
* Verifies the code and select the provided identifier as primary.
|
|
234
|
+
*
|
|
235
|
+
* @param params - Parameters for verification.
|
|
236
|
+
* @param params.code - The one-time code sent to the identifier.
|
|
237
|
+
* @param params.identifier - The one-time code sent to the identifier.
|
|
238
|
+
*
|
|
239
|
+
* @returns A Promise resolving to a result object:
|
|
240
|
+
* - On success: `BaseSuccessReturn` with optional `user`.
|
|
241
|
+
* - On failure: `BaseFailureReturn` with optional `verifyAttempt` (email or phone resource) and `user`.
|
|
242
|
+
*/
|
|
243
|
+
verifyCode: (params: {
|
|
244
|
+
code: string;
|
|
245
|
+
identifier: string;
|
|
246
|
+
}) => Promise<(BaseSuccessReturn | (BaseFailureReturn & {
|
|
247
|
+
verifyAttempt?: PhoneNumberResource | EmailAddressResource;
|
|
248
|
+
})) & {
|
|
249
|
+
user?: UserResource | null;
|
|
250
|
+
}>;
|
|
251
|
+
/** Indicates whether a update identifier request is currently being processed. `true` or `false` */
|
|
252
|
+
isUpdating: boolean;
|
|
253
|
+
}
|
|
254
|
+
/** Type for authentication identifier methods */
|
|
255
|
+
type AuthIdentifierMethod = 'emailAddress' | 'phoneNumber' | 'username';
|
|
256
|
+
/** Type for authentication verification methods */
|
|
257
|
+
type AuthIdentifierVerifyBy = 'otp' | 'password';
|
|
258
|
+
/**
|
|
259
|
+
* Maps verification method to the allowed identifier methods.
|
|
260
|
+
*
|
|
261
|
+
* - For `'otp'`, only email and phone are allowed.
|
|
262
|
+
* - For `'password'`, all methods are allowed.
|
|
263
|
+
*/
|
|
264
|
+
type IdentifierMethodFor<VerifyBy extends AuthIdentifierVerifyBy> = VerifyBy extends 'otp' ? Exclude<AuthIdentifierMethod, 'username'> : AuthIdentifierMethod;
|
|
265
|
+
/**
|
|
266
|
+
* Parameters for starting an authentication flow, based on the selected verification method.
|
|
267
|
+
*
|
|
268
|
+
* - For `'otp'`: requires only an identifier (email or phone).
|
|
269
|
+
* - For `'password'`: requires identifier and password, and optionally a token template.
|
|
270
|
+
*/
|
|
271
|
+
type StartAuthParams<VerifyBy extends AuthIdentifierVerifyBy> = VerifyBy extends 'otp' ? {
|
|
272
|
+
/** Identifier (email address or phone number). */
|
|
273
|
+
identifier: string;
|
|
274
|
+
} : {
|
|
275
|
+
/** Identifier (email address, phone number, or username). */
|
|
276
|
+
identifier: string;
|
|
277
|
+
/** User's password. */
|
|
278
|
+
password: string;
|
|
279
|
+
/** Optional name of a token template for customizing the session token. */
|
|
280
|
+
tokenTemplate?: string;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Return type for starting a sign-in flow.
|
|
284
|
+
*
|
|
285
|
+
* - For `'password'`: may include a `sessionToken`.
|
|
286
|
+
* - For `'otp'`: standard return type.
|
|
287
|
+
*/
|
|
288
|
+
type StartSignInWithIdentifierReturn<VerifyBy extends AuthIdentifierVerifyBy> = VerifyBy extends 'password' ? StartSignInReturn & {
|
|
289
|
+
/** Optional session token returned upon successful password sign-in. */
|
|
290
|
+
sessionToken?: string;
|
|
291
|
+
} : StartSignInReturn;
|
|
292
|
+
/**
|
|
293
|
+
* Return type for starting a sign-up flow.
|
|
294
|
+
*
|
|
295
|
+
* - For `'username'`: may include a `sessionToken`.
|
|
296
|
+
* - For others: standard return type.
|
|
297
|
+
*/
|
|
298
|
+
type StartSignUpWithIdentifierReturn<Method extends AuthIdentifierMethod> = Method extends 'username' ? StartSignUpReturn & {
|
|
299
|
+
/** Optional session token returned upon successful username sign-up. */
|
|
300
|
+
sessionToken?: string;
|
|
301
|
+
} : StartSignUpReturn;
|
|
302
|
+
/**
|
|
303
|
+
* Return type for starting a generic authorization (sign-up or sign-in).
|
|
304
|
+
*
|
|
305
|
+
* - For `'username'`: may include a `sessionToken`.
|
|
306
|
+
* - For others: standard return type.
|
|
307
|
+
*/
|
|
308
|
+
type StartAuthorizationWithIdentifierReturn<Method extends AuthIdentifierMethod> = Method extends 'username' ? StartAuthorizationReturn & {
|
|
309
|
+
/** Optional session token returned upon successful username authorization. */
|
|
310
|
+
sessionToken?: string;
|
|
311
|
+
} : StartAuthorizationReturn;
|
|
312
|
+
type StartSignUpParams<VerifyBy extends AuthIdentifierVerifyBy> = StartAuthParams<VerifyBy> & SignUpParams;
|
|
313
|
+
/**
|
|
314
|
+
* Base return type for useAuthWithIdentifier hook.
|
|
315
|
+
*
|
|
316
|
+
* Provides common methods and status flags for both verification methods (`otp`, `password`).
|
|
317
|
+
*/
|
|
318
|
+
interface BaseUseAuthWithIdentifierReturn<VerifyBy extends AuthIdentifierVerifyBy> {
|
|
319
|
+
/**
|
|
320
|
+
* Initiates the sign-in flow using the provided identifier and verification method.
|
|
321
|
+
*
|
|
322
|
+
* @param params - Authentication parameters depending on `VerifyBy` type.
|
|
323
|
+
* @returns A Promise resolving to a result of sign-in attempt.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* // Example for email + password
|
|
327
|
+
* await startSignIn({
|
|
328
|
+
* identifier: 'user@example.com',
|
|
329
|
+
* password: 'securePassword123'
|
|
330
|
+
* });
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* // Example for phone + OTP
|
|
334
|
+
* await startSignIn({
|
|
335
|
+
* identifier: '+1234567890'
|
|
336
|
+
* });
|
|
337
|
+
*/
|
|
338
|
+
startSignIn: (params: StartAuthParams<VerifyBy>) => Promise<StartSignInWithIdentifierReturn<VerifyBy>>;
|
|
339
|
+
/**
|
|
340
|
+
* Initiates the sign-up flow using the provided identifier and verification method.
|
|
341
|
+
*
|
|
342
|
+
* @param params - Authentication parameters depending on `VerifyBy` type.
|
|
343
|
+
* @returns A Promise resolving to a result of sign-up attempt.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* // Example 1: Sign up with email + OTP
|
|
347
|
+
* await startSignUp({
|
|
348
|
+
* identifier: 'user@example.com',
|
|
349
|
+
* });
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* // Example 2: Sign up with phone + OTP
|
|
353
|
+
* await startSignUp({
|
|
354
|
+
* identifier: '+1234567890',
|
|
355
|
+
* });
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* // Example 3: Sign up with username + password
|
|
359
|
+
* await startSignUp({
|
|
360
|
+
* identifier: 'username',
|
|
361
|
+
* password: 'password!'
|
|
362
|
+
* });
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* // Example 4: Sign up with email + password + custom token template
|
|
366
|
+
* await startSignUp({
|
|
367
|
+
* identifier: 'user@example.com',
|
|
368
|
+
* password: 'password',
|
|
369
|
+
* tokenTemplate: 'my_template'
|
|
370
|
+
* });
|
|
371
|
+
*/
|
|
372
|
+
startSignUp: (params: StartSignUpParams<VerifyBy>) => Promise<StartSignUpWithIdentifierReturn<any>>;
|
|
373
|
+
/**
|
|
374
|
+
* Initiates a combined authorization flow (sign-up or sign-in) based on user existence.
|
|
375
|
+
*
|
|
376
|
+
* @param params - Authentication parameters depending on `VerifyBy` type.
|
|
377
|
+
* @returns A Promise resolving to a result of the authorization flow.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* // Example 1: Authorize with email + OTP (sign-in or sign-up automatically)
|
|
381
|
+
* await startAuthorization({
|
|
382
|
+
* identifier: 'user@example.com',
|
|
383
|
+
* });
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* // Example 2: Authorize with phone + OTP
|
|
387
|
+
* await startAuthorization({
|
|
388
|
+
* identifier: '+1234567890',
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* // Example 3: Authorize with username + password
|
|
393
|
+
* await startAuthorization({
|
|
394
|
+
* identifier: 'username',
|
|
395
|
+
* password: 'password'
|
|
396
|
+
* });
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* // Example 4: Authorize with email + password + token template
|
|
400
|
+
* await startAuthorization({
|
|
401
|
+
* identifier: 'user@example.com',
|
|
402
|
+
* password: 'password',
|
|
403
|
+
* tokenTemplate: 'my_template'
|
|
404
|
+
* });
|
|
405
|
+
*/
|
|
406
|
+
startAuthorization: (params: StartAuthParams<VerifyBy>) => Promise<StartAuthorizationWithIdentifierReturn<any>>;
|
|
407
|
+
/** Indicates whether an authentication request is currently being processed. `true` or `false` */
|
|
408
|
+
isLoading: boolean;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Conditional return type for `useAuthWithIdentifier` depending on identifier method.
|
|
412
|
+
*
|
|
413
|
+
* - Adds OTP-specific fields (`verifyCode`, `isVerifying`) for `emailAddress` and `phoneNumber`.
|
|
414
|
+
* - These fields are omitted for `username`.
|
|
415
|
+
*/
|
|
416
|
+
type ConditionalUseAuthWithIdentifierReturn<VerifyBy extends AuthIdentifierVerifyBy, Method extends AuthIdentifierMethod> = Method extends 'username' ? BaseUseAuthWithIdentifierReturn<VerifyBy> : BaseUseAuthWithIdentifierReturn<VerifyBy> & {
|
|
417
|
+
/**
|
|
418
|
+
* Verifies the OTP code sent to the user.
|
|
419
|
+
*
|
|
420
|
+
* Only available when using `emailAddress` or `phoneNumber`.
|
|
421
|
+
*
|
|
422
|
+
* @param params.code - The one-time code entered by the user.
|
|
423
|
+
* @param params.isSignUp - Whether the flow is sign-up (true) or sign-in (false).
|
|
424
|
+
* @param params.tokenTemplate - (Optional) Token template to customize the session.
|
|
425
|
+
* @returns A Promise resolving to the final result of the authorization flow.
|
|
426
|
+
*/
|
|
427
|
+
verifyCode: (params: {
|
|
428
|
+
code: string;
|
|
429
|
+
isSignUp: boolean;
|
|
430
|
+
tokenTemplate?: string;
|
|
431
|
+
}) => Promise<AuthorizationFinishedReturn>;
|
|
432
|
+
/** Indicates whether OTP verification is currently in progress. `true` or `false` */
|
|
433
|
+
isVerifying: boolean;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Final return type of `useAuthWithIdentifier` hook.
|
|
437
|
+
*
|
|
438
|
+
* - Includes all sign-in, sign-up, and authorization methods.
|
|
439
|
+
* - May include `verifyCode` and `isVerifying` if applicable.
|
|
440
|
+
*
|
|
441
|
+
* @template VerifyBy - Verification method used (`otp` or `password`)
|
|
442
|
+
* @template Method - Identifier method used (`emailAddress`, `phoneNumber`, `username`)
|
|
443
|
+
*/
|
|
444
|
+
type UseAuthWithIdentifierReturn<VerifyBy extends AuthIdentifierVerifyBy, Method extends AuthIdentifierMethod> = ConditionalUseAuthWithIdentifierReturn<VerifyBy, Method>;
|
|
445
|
+
/** Return type for a hook that manages the password reset process. */
|
|
446
|
+
interface UseResetPasswordReturn {
|
|
447
|
+
/**
|
|
448
|
+
* Initiates the password reset process for the given identifier.
|
|
449
|
+
*
|
|
450
|
+
* This sends a verification code (e.g., via email or SMS) to the provided identifier.
|
|
451
|
+
*
|
|
452
|
+
* @param params - Parameters required to start the password reset process.
|
|
453
|
+
* @param params.identifier - The user's identifier (email address or phone number).
|
|
454
|
+
*
|
|
455
|
+
* @returns A Promise resolving to a result object:
|
|
456
|
+
* - On success: `BaseSuccessReturn` with sign-in context via `WithSignInReturn`.
|
|
457
|
+
* - On failure: `BaseFailureReturn` with possible error information.
|
|
458
|
+
*/
|
|
459
|
+
startResetPassword: (params: {
|
|
460
|
+
identifier: string;
|
|
461
|
+
}) => Promise<(BaseSuccessReturn | BaseFailureReturn) & WithSignInReturn>;
|
|
462
|
+
/**
|
|
463
|
+
* Verifies the code sent to the newly added identifier.
|
|
464
|
+
*
|
|
465
|
+
* @param params - Parameters for verification.
|
|
466
|
+
* @param params.code - The one-time code sent to the identifier.
|
|
467
|
+
*
|
|
468
|
+
* @returns A Promise resolving to a result object:
|
|
469
|
+
* - On success: `BaseSuccessReturn` with optional `user`.
|
|
470
|
+
* - On failure: `BaseFailureReturn` with optional `verifyAttempt` (email or phone resource) and `user`.
|
|
471
|
+
*/
|
|
472
|
+
verifyCode: (params: {
|
|
473
|
+
code: string;
|
|
474
|
+
}) => Promise<BaseSuccessReturn | (BaseFailureReturn & {
|
|
475
|
+
verifyAttempt?: PhoneNumberResource | EmailAddressResource;
|
|
476
|
+
})>;
|
|
477
|
+
/**
|
|
478
|
+
* Completes the password reset process using the provided verification code and new password.
|
|
479
|
+
*
|
|
480
|
+
* @param params - Parameters required to reset the password.
|
|
481
|
+
* @param params.password - The new password to be set.
|
|
482
|
+
* @param params.tokenTemplate - (Optional) A token template name to use when creating the session token.
|
|
483
|
+
*
|
|
484
|
+
* @returns A Promise resolving to an `AuthorizationFinishedReturn`, which includes:
|
|
485
|
+
* - `isSuccess`: Indicates whether the password reset was successful.
|
|
486
|
+
* - `sessionToken`: A session token if authentication is completed.
|
|
487
|
+
*/
|
|
488
|
+
resetPassword: (params: {
|
|
489
|
+
password: string;
|
|
490
|
+
tokenTemplate?: string;
|
|
491
|
+
}) => Promise<StartSignInReturn & {
|
|
492
|
+
sessionToken?: string;
|
|
493
|
+
}>;
|
|
494
|
+
/** Indicates whether the password reset operation is currently in progress. `true` or `false` */
|
|
495
|
+
isResetting: boolean;
|
|
496
|
+
/** Indicates whether the code for password reset is currently being sent. `true` or `false` */
|
|
497
|
+
isCodeSending: boolean;
|
|
498
|
+
/** Indicates whether a verification request is currently being processed via `verifyCode`. `true` or `false` */
|
|
499
|
+
isVerifying: boolean;
|
|
500
|
+
}
|
|
501
|
+
interface UseUpdatePasswordReturn {
|
|
502
|
+
/**
|
|
503
|
+
* Initiates the password reset process for the given identifier.
|
|
504
|
+
*
|
|
505
|
+
* @returns A Promise resolving to a result object:
|
|
506
|
+
* - On success: `BaseSuccessReturn` with sign-in context via `WithSignInReturn`.
|
|
507
|
+
* - On failure: `BaseFailureReturn` with possible error information.
|
|
508
|
+
*/
|
|
509
|
+
updatePassword: (params: UpdateUserPasswordParams) => Promise<BaseSuccessReturn | BaseFailureReturn>;
|
|
510
|
+
/** Indicates whether the code for password reset is currently being sent. `true` or `false` */
|
|
511
|
+
isPasswordUpdating: boolean;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Hook that provides access to essential Clerk methods and objects.
|
|
516
|
+
*
|
|
517
|
+
* @returns {UseClerkResourcesReturn} Object containing Clerk resources:
|
|
518
|
+
* - `signUp` - Provides access to SignUp object: https://clerk.com/docs/references/javascript/sign-up
|
|
519
|
+
* - `signIn` - Provides access to SignIn object: https://clerk.com/docs/references/javascript/sign-in
|
|
520
|
+
* - `setActive` - A function that sets the active session
|
|
521
|
+
* - `signOut` - A function that signs out the current user
|
|
522
|
+
*/
|
|
523
|
+
declare const useClerkResources: () => UseClerkResourcesReturn;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Hook that provides functionality for getting session tokens.
|
|
527
|
+
*
|
|
528
|
+
* @returns {UseGetSessionTokenReturn} Object containing:
|
|
529
|
+
* - `getSessionToken` - A function to retrieve the session token. It takes an optional tokenTemplate parameter to specify a template for the token
|
|
530
|
+
*/
|
|
531
|
+
declare const useGetSessionToken: () => UseGetSessionTokenReturn;
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Hook that provides functionality to handle SSO authentication flows.
|
|
535
|
+
*
|
|
536
|
+
* @returns {UseAuthWithSSOReturn} Object containing:
|
|
537
|
+
* - `startSSOFlow` - A function to initiate an SSO flow. It takes a strategy, redirectUrl, and optional tokenTemplate as parameters, starting the SSO authentication and returning session information or errors upon completion
|
|
538
|
+
* - `isLoading` - A boolean indicating whether an SSO process is currently ongoing
|
|
539
|
+
*/
|
|
540
|
+
declare function useAuthWithSSO(): UseAuthWithSSOReturn;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Hook that facilitates user authentication using a ticket-based strategy (ticket is a token generated from the Backend API).
|
|
544
|
+
*
|
|
545
|
+
* @returns {UseAuthWithTicketReturn} Object containing:
|
|
546
|
+
* - `startAuthorization` - A function to initiate authentication with a ticket. It accepts an object with ticket and optional tokenTemplate parameters to kick off the authorization process and returns the session details
|
|
547
|
+
* - `isLoading` - A boolean indicating whether the ticket-based authorization process is ongoing
|
|
548
|
+
*/
|
|
549
|
+
declare function useAuthWithTicket(): UseAuthWithTicketReturn;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Hook that provides functionality for managing OTP (One Time Password) verification in user authentication workflows, supporting both sign-up and sign-in processes.
|
|
553
|
+
*
|
|
554
|
+
* @returns {UseOtpVerificationReturn} Object containing:
|
|
555
|
+
* - `sendOtpCode` - Sends an OTP code to the user's identifier (email or phone number) based on the specified strategy
|
|
556
|
+
* - `verifyCode` - Verifies the OTP code provided by the user, completing the authentication process
|
|
557
|
+
* - `isVerifying` - A boolean indicating whether a verification attempt is currently in progress
|
|
558
|
+
*/
|
|
559
|
+
declare function useOtpVerification(): UseOtpVerificationReturn;
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* 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.
|
|
563
|
+
*
|
|
564
|
+
* @template {AuthIdentifierVerifyBy} TVerifyBy - The verification method type
|
|
565
|
+
* @template {IdentifierMethodFor<TVerifyBy>} TMethod - The identifier method type
|
|
566
|
+
* @param {TMethod} method - Specifies the type of identifier used for authentication (e.g., 'emailAddress', 'phoneNumber', 'username')
|
|
567
|
+
* @param {TVerifyBy} verifyBy - Specifies the verification method ('otp' for one-time passwords or 'password')
|
|
568
|
+
*
|
|
569
|
+
* @returns {UseAuthWithIdentifierReturn<TVerifyBy, TMethod>} Object containing:
|
|
570
|
+
* - `startSignUp` - Initiates a new user registration using the specified identifier and verification method
|
|
571
|
+
* - `startSignIn` - Initiates authentication of an existing user using the specified identifier and verification method
|
|
572
|
+
* - `startAuthorization` - Determines whether to initiate a sign-up or sign-in based on whether the user has been registered previously
|
|
573
|
+
* - `verifyCode` - Verifies an OTP code if the verification method is 'otp' (only available for non-username methods)
|
|
574
|
+
* - `isLoading` - Indicates whether an authentication request is in progress
|
|
575
|
+
* - `isVerifying` - Indicates whether an OTP verification is in progress (only available for non-username methods)
|
|
576
|
+
*/
|
|
577
|
+
declare function useAuthWithIdentifier<TVerifyBy extends AuthIdentifierVerifyBy, TMethod extends IdentifierMethodFor<TVerifyBy>>(method: TMethod, verifyBy: TVerifyBy): UseAuthWithIdentifierReturn<TVerifyBy, TMethod>;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Hook that provides functionality to add new email or phone number identifiers to a user's account and verify them using verification codes.
|
|
581
|
+
*
|
|
582
|
+
* @param {IdentifierType} type - Specifies the type of identifier (e.g., 'phone', 'email')
|
|
583
|
+
*
|
|
584
|
+
* @returns {UseAddIdentifierReturn} Object containing:
|
|
585
|
+
* - `createIdentifier` - A function to add a new email or phone number identifier to the user's account and prepare it for verification
|
|
586
|
+
* - `verifyCode` - A function to verify a code sent to the identifier, completing the verification process
|
|
587
|
+
* - `isCreating` - A boolean indicating whether an identifier is currently being added
|
|
588
|
+
* - `isVerifying` - A boolean indicating whether a verification code is currently being processed
|
|
589
|
+
*/
|
|
590
|
+
declare function useAddIdentifier(type: IdentifierType): UseAddIdentifierReturn;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Hook that provides methods to handle password reset functionality through email or phone-based OTP.
|
|
594
|
+
*
|
|
595
|
+
* @param {Object} params - Parameters for the hook
|
|
596
|
+
* @param {OtpMethod} params.method - The method to use for OTP (emailAddress or phoneNumber)
|
|
597
|
+
*
|
|
598
|
+
* @returns {UseResetPasswordReturn} Object containing:
|
|
599
|
+
* - `startResetPassword` - A function to initiate the password reset process by sending a verification code to the user's email or phone number
|
|
600
|
+
* - `resetPassword` - A function to reset the user's password and setting a new password
|
|
601
|
+
* - `verifyCode` - A function to verify a code sent to the identifier, completing the verification process
|
|
602
|
+
* - `isCodeSending` - A boolean indicating if the verification code is being sent
|
|
603
|
+
* - `isResetting` - A boolean indicating if the password is being reset
|
|
604
|
+
* - `isVerifying` - A boolean indicating whether a verification code is currently being processed
|
|
605
|
+
*/
|
|
606
|
+
declare function useResetPassword({ method }: {
|
|
607
|
+
method: OtpMethod;
|
|
608
|
+
}): UseResetPasswordReturn;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Hook that provides functionality to update the current user's password.
|
|
612
|
+
*
|
|
613
|
+
* Requires the user to supply both the current password (for verification) and
|
|
614
|
+
* the new password. On success, the user's password is updated in Clerk; on
|
|
615
|
+
* failure, the hook returns an error without throwing.
|
|
616
|
+
*
|
|
617
|
+
* @returns {UseUpdatePasswordReturn} Object containing:
|
|
618
|
+
* - `updatePassword` — Updates the user's password using current and new password
|
|
619
|
+
* - `isPasswordUpdating` — Indicates whether a password update is currently in progress
|
|
620
|
+
*/
|
|
621
|
+
declare const useChangePassword: () => UseUpdatePasswordReturn;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Hook that provides functionality to update an existing primary identifier
|
|
625
|
+
* (email address or phone number) for the current user.
|
|
626
|
+
*
|
|
627
|
+
* This hook is a higher-level abstraction built on top of `useAddIdentifier`.
|
|
628
|
+
* It reuses the identifier creation and verification flow, but extends it with
|
|
629
|
+
* additional logic that, upon successful verification, automatically:
|
|
630
|
+
*
|
|
631
|
+
* - Sets the newly verified identifier as the primary one
|
|
632
|
+
* - Removes the previously primary identifier (if different)
|
|
633
|
+
*
|
|
634
|
+
* The update process follows these stages:
|
|
635
|
+
* 1. `createIdentifier` — adds a new identifier and initiates its verification flow
|
|
636
|
+
* 2. `verifyCode` — verifies the received code and, if successful, updates the
|
|
637
|
+
* user's primary identifier
|
|
638
|
+
*
|
|
639
|
+
* All basic method signatures and return types are inherited from `useAddIdentifier`, ensuring full compatibility
|
|
640
|
+
*
|
|
641
|
+
* @param {IdentifierType} type - Specifies the type of identifier (e.g., 'phone', 'email')
|
|
642
|
+
*
|
|
643
|
+
* @returns {UseUpdateIdentifierReturn} Object containing:
|
|
644
|
+
* - `createIdentifier` — Adds a new email or phone identifier and prepares it for verification
|
|
645
|
+
* - `verifyCode` — Verifies the code sent to the identifier and, on success,
|
|
646
|
+
* updates the user's primary identifier
|
|
647
|
+
* - `isCreating` — Indicates whether an identifier is currently being added
|
|
648
|
+
* - `isVerifying` — Indicates whether a verification request is currently being processed
|
|
649
|
+
* - `isUpdating` — Indicates whether the primary identifier update is currently in progress
|
|
650
|
+
*/
|
|
651
|
+
declare function useUpdateIdentifier(type: IdentifierType): UseUpdateIdentifierReturn;
|
|
652
|
+
|
|
653
|
+
export { type AuthIdentifierMethod, type AuthIdentifierVerifyBy, type AuthorizationFinishedReturn, ClerkApiError, type GetSessionTokenFn, type GetSessionTokenReturn, type IdentifierMethodFor, type IdentifierType, type OtpMethod, type OtpStrategy, type SignUpParams, type StartAuthParams, type StartAuthorizationWithIdentifierReturn, type StartAuthorizationWithTicketReturn, type StartSSOArgs, type StartSignInWithIdentifierReturn, type StartSignUpParams, type StartSignUpWithIdentifierReturn, type UseAddIdentifierReturn, type UseAuthWithIdentifierReturn, type UseAuthWithSSOReturn, type UseAuthWithTicketReturn, type UseClerkResourcesReturn, type UseGetSessionTokenReturn, type UseOtpVerificationReturn, type UseResetPasswordReturn, type UseUpdateIdentifierReturn, type UseUpdatePasswordReturn, useAddIdentifier, useAuthWithIdentifier, useAuthWithSSO, useAuthWithTicket, useChangePassword, useClerkResources, useGetSessionToken, useOtpVerification, useResetPassword, useUpdateIdentifier };
|