File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import type {
18
18
ExchangeNativeSocialOptions ,
19
19
RevokeOptions ,
20
20
ResetPasswordOptions ,
21
+ CreateUserOptions ,
21
22
} from '../types' ;
22
23
import BaseError from '../utils/baseError' ;
23
24
@@ -138,6 +139,12 @@ export interface Auth0ContextInterface<TUser extends User = User>
138
139
*Request an email with instructions to change password of a user {@link Auth#resetPassword}
139
140
*/
140
141
resetPassword : ( parameters : ResetPasswordOptions ) => Promise < void > ;
142
+
143
+
144
+ /**
145
+ *Creates a new user {@link Auth#createUser}
146
+ */
147
+ createUser : ( parameters : CreateUserOptions ) => Promise < Partial < User > > ;
141
148
}
142
149
143
150
export interface AuthState < TUser extends User = User > {
@@ -181,6 +188,7 @@ const initialContext = {
181
188
authorizeWithExchangeNativeSocial : stub ,
182
189
revokeRefreshToken : stub ,
183
190
resetPassword : stub ,
191
+ createUser : stub ,
184
192
} ;
185
193
186
194
const Auth0Context = createContext < Auth0ContextInterface > ( initialContext ) ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import type {
24
24
ExchangeNativeSocialOptions ,
25
25
RevokeOptions ,
26
26
ResetPasswordOptions ,
27
+ CreateUserOptions ,
27
28
} from '../types' ;
28
29
import type { CustomJwtPayload } from '../internal-types' ;
29
30
import { convertUser } from '../utils/userConversion' ;
@@ -390,6 +391,19 @@ const Auth0Provider = ({
390
391
}
391
392
} , [ client ] ) ;
392
393
394
+ const createUser = useCallback (
395
+ async ( parameters : CreateUserOptions ) => {
396
+ try {
397
+ const user = await client . auth . createUser ( parameters ) ;
398
+ return user ;
399
+ } catch ( error ) {
400
+ dispatch ( { type : 'ERROR' , error : error as BaseError } ) ;
401
+ throw error ;
402
+ }
403
+ } ,
404
+ [ client ]
405
+ ) ;
406
+
393
407
const contextValue = useMemo (
394
408
( ) => ( {
395
409
...state ,
@@ -411,6 +425,7 @@ const Auth0Provider = ({
411
425
authorizeWithExchangeNativeSocial,
412
426
revokeRefreshToken,
413
427
resetPassword,
428
+ createUser,
414
429
} ) ,
415
430
[
416
431
state ,
@@ -432,6 +447,7 @@ const Auth0Provider = ({
432
447
authorizeWithExchangeNativeSocial ,
433
448
revokeRefreshToken ,
434
449
resetPassword ,
450
+ createUser ,
435
451
]
436
452
) ;
437
453
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import type { Auth0ContextInterface } from './auth0-context';
30
30
* authorizeWithPasswordRealm,
31
31
* authorizeWithExchangeNativeSocial,
32
32
* revokeRefreshToken
33
+ * createUser
33
34
* } = useAuth0();
34
35
* ```
35
36
*
You can’t perform that action at this time.
0 commit comments