File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
packages/next/src/views/CreateFirstUser Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use client'
2
- import type { ClientCollectionConfig , FormState , LoginWithUsernameOptions } from 'payload'
2
+ import type {
3
+ ClientCollectionConfig ,
4
+ ClientUser ,
5
+ FormState ,
6
+ LoginWithUsernameOptions ,
7
+ } from 'payload'
3
8
4
9
import {
5
10
ConfirmPasswordField ,
@@ -8,6 +13,7 @@ import {
8
13
FormSubmit ,
9
14
PasswordField ,
10
15
RenderFields ,
16
+ useAuth ,
11
17
useConfig ,
12
18
useTranslation ,
13
19
} from '@payloadcms/ui'
@@ -30,6 +36,7 @@ export const CreateFirstUserClient: React.FC<{
30
36
} = useConfig ( )
31
37
32
38
const { t } = useTranslation ( )
39
+ const { setUser } = useAuth ( )
33
40
34
41
const collectionConfig = getEntityConfig ( { collectionSlug : userSlug } ) as ClientCollectionConfig
35
42
@@ -50,12 +57,17 @@ export const CreateFirstUserClient: React.FC<{
50
57
[ apiRoute , userSlug , serverURL ] ,
51
58
)
52
59
60
+ const handleFirstRegister = ( data : { user : ClientUser } ) => {
61
+ setUser ( data . user )
62
+ }
63
+
53
64
return (
54
65
< Form
55
66
action = { `${ serverURL } ${ apiRoute } /${ userSlug } /first-register` }
56
67
initialState = { initialState }
57
68
method = "POST"
58
69
onChange = { [ onChange ] }
70
+ onSuccess = { handleFirstRegister }
59
71
redirect = { admin }
60
72
validationOperation = "create"
61
73
>
You can’t perform that action at this time.
0 commit comments