From 65cd15aba523a43779091591886f3f42ac9809b5 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Sun, 6 Aug 2023 15:49:24 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20direct=20sign=20in?= =?UTF-8?q?=20after=20onboarding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/onboard.tsx | 65 ++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/src/pages/onboard.tsx b/src/pages/onboard.tsx index 02e8bf363..18a579ad6 100644 --- a/src/pages/onboard.tsx +++ b/src/pages/onboard.tsx @@ -21,6 +21,8 @@ import { useMediaQuery } from '@mantine/hooks'; import { IconLayoutDashboard, IconUserCog } from '@tabler/icons-react'; import { IconArrowRight, IconBook2, IconUserPlus } from '@tabler/icons-react'; import { GetServerSideProps } from 'next'; +import { signIn } from 'next-auth/react'; +import Head from 'next/head'; import Link from 'next/link'; import { ReactNode, useMemo, useState } from 'react'; import { z } from 'zod'; @@ -42,26 +44,32 @@ export default function OnboardPage() { const background = colorScheme === 'dark' ? 'dark.6' : 'gray.1'; return ( - -
-
- Homarr Logo + <> + + Onboard • Homarr + + + +
+
+ Homarr Logo +
-
- - - {stepContents.map((_, index) => ( - - ))} - - + + + {stepContents.map((_, index) => ( + + ))} + + + - + ); } @@ -101,7 +109,8 @@ const FirstStepContent: StepContentComponent = ({ isMobile, next }) => { }; const SecondStepContent: StepContentComponent = ({ isMobile, next }) => { - const { mutateAsync, isLoading } = api.user.createAdminAccount.useMutation(); + const [isSigninIn, setIsSigninIn] = useState(false); + const { mutateAsync } = api.user.createAdminAccount.useMutation(); const { i18nZodResolver } = useI18nZodResolver(); const form = useForm>({ @@ -109,9 +118,21 @@ const SecondStepContent: StepContentComponent = ({ isMobile, next }) => { validateInputOnBlur: true, }); const handleSubmit = (values: z.infer) => { + setIsSigninIn(true); void mutateAsync(values, { onSuccess: () => { - next(); + signIn('credentials', { + redirect: false, + name: values.username, + password: values.password, + callbackUrl: '/', + }).then((response) => { + if (!response?.ok) { + setIsSigninIn(false); + return; + } + next(); + }); }, }); }; @@ -147,7 +168,7 @@ const SecondStepContent: StepContentComponent = ({ isMobile, next }) => { withAsterisk {...form.getInputProps('passwordConfirmation')} /> - @@ -165,7 +186,7 @@ const firstActions = [ { icon: IconUserPlus, label: 'Invite an user', - href: '/users/invite', + href: '/manage/users/invites', }, { icon: IconLayoutDashboard,