From 0118bce58275d8f146c6e51071cbcaab99df7515 Mon Sep 17 00:00:00 2001 From: Sasha Date: Tue, 10 Sep 2024 22:04:42 +0300 Subject: [PATCH] fix(next): set the user data before redirect after login (#8135) ## Description Fixes https://github.com/payloadcms/payload/issues/8134 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] Existing test suite passes locally with my changes --- packages/next/src/views/Login/LoginForm/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/next/src/views/Login/LoginForm/index.tsx b/packages/next/src/views/Login/LoginForm/index.tsx index 7b95412e418..dfda6e81f10 100644 --- a/packages/next/src/views/Login/LoginForm/index.tsx +++ b/packages/next/src/views/Login/LoginForm/index.tsx @@ -6,9 +6,9 @@ import React from 'react' const baseClass = 'login__form' const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default -import type { FormState } from 'payload' +import type { ClientUser, FormState } from 'payload' -import { Form, FormSubmit, PasswordField, useConfig, useTranslation } from '@payloadcms/ui' +import { Form, FormSubmit, PasswordField, useAuth, useConfig, useTranslation } from '@payloadcms/ui' import { formatAdminURL } from '@payloadcms/ui/shared' import type { LoginFieldProps } from '../LoginField/index.js' @@ -50,6 +50,7 @@ export const LoginForm: React.FC<{ }) const { t } = useTranslation() + const { setUser } = useAuth() const initialState: FormState = { password: { @@ -73,6 +74,10 @@ export const LoginForm: React.FC<{ } } + const handleLogin = (data: { user: ClientUser }) => { + setUser(data.user) + } + return (