feat: option to pre-fill login credentials automatically (#3021)

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Alessio Gravili
2023-08-04 19:41:08 +02:00
committed by GitHub
parent 356f174b9f
commit c5756ed4a1
7 changed files with 61 additions and 9 deletions

View File

@@ -144,7 +144,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
setUser(json.user);
} else if (json?.token) {
setToken(json.token);
} else if (autoLogin) {
} else if (autoLogin && autoLogin.prefillOnly !== true) {
// auto log-in with the provided autoLogin credentials. This is used in dev mode
// so you don't have to log in over and over again
const autoLoginResult = await requests.post(`${serverURL}${api}/${userSlug}/login`, {

View File

@@ -26,6 +26,7 @@ const Login: React.FC = () => {
admin: {
user: userSlug,
logoutRoute,
autoLogin,
components: {
beforeLogin,
afterLogin,
@@ -103,6 +104,10 @@ const Login: React.FC = () => {
onSuccess={onSuccess}
method="post"
action={`${serverURL}${api}/${userSlug}/login`}
initialData={{
email: autoLogin && autoLogin.prefillOnly ? autoLogin.email : undefined,
password: autoLogin && autoLogin.prefillOnly ? autoLogin.password : undefined,
}}
>
<FormLoadingOverlayToggle
action="loading"