Skip to content

Commit 30eb1d5

Browse files
authored
fix(next): set the user data after first user registration (#8360)
Fixes #8353 by analogy with #8135
1 parent dedcff0 commit 30eb1d5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/next/src/views/CreateFirstUser/index.client.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
'use client'
2-
import type { ClientCollectionConfig, FormState, LoginWithUsernameOptions } from 'payload'
2+
import type {
3+
ClientCollectionConfig,
4+
ClientUser,
5+
FormState,
6+
LoginWithUsernameOptions,
7+
} from 'payload'
38

49
import {
510
ConfirmPasswordField,
@@ -8,6 +13,7 @@ import {
813
FormSubmit,
914
PasswordField,
1015
RenderFields,
16+
useAuth,
1117
useConfig,
1218
useTranslation,
1319
} from '@payloadcms/ui'
@@ -30,6 +36,7 @@ export const CreateFirstUserClient: React.FC<{
3036
} = useConfig()
3137

3238
const { t } = useTranslation()
39+
const { setUser } = useAuth()
3340

3441
const collectionConfig = getEntityConfig({ collectionSlug: userSlug }) as ClientCollectionConfig
3542

@@ -50,12 +57,17 @@ export const CreateFirstUserClient: React.FC<{
5057
[apiRoute, userSlug, serverURL],
5158
)
5259

60+
const handleFirstRegister = (data: { user: ClientUser }) => {
61+
setUser(data.user)
62+
}
63+
5364
return (
5465
<Form
5566
action={`${serverURL}${apiRoute}/${userSlug}/first-register`}
5667
initialState={initialState}
5768
method="POST"
5869
onChange={[onChange]}
70+
onSuccess={handleFirstRegister}
5971
redirect={admin}
6072
validationOperation="create"
6173
>

0 commit comments

Comments
 (0)