Skip to content

Commit 0d0b908

Browse files
WIP. remake auth
1 parent 08690f2 commit 0d0b908

6 files changed

Lines changed: 55 additions & 41 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use client'
2+
import { use } from 'react';
3+
import { notFound } from 'next/navigation';
4+
import { SingleCard } from '@/layouts';
5+
import { LoginForm, CreateAccountForm, ResetPasswordForm } from '@/components'
6+
7+
const formText = {
8+
'login': {
9+
title: 'Sign In'
10+
},
11+
'create-account': {
12+
title: 'Sign Up'
13+
},
14+
'reset-password': {
15+
title: 'Reset Password',
16+
description: 'Please enter the email address that you used to register, and we will send you a link to reset your password via Email.'
17+
}
18+
}
19+
20+
function AuthForm({name}) {
21+
switch (name) {
22+
case 'login': return <LoginForm />;
23+
case 'create-account': return <CreateAccountForm />;
24+
case 'reset-password': return <ResetPasswordForm />;
25+
}
26+
}
27+
28+
export default function AuthPage({ params }) {
29+
const { type } = use(params)
30+
31+
if (!formText[type]) {
32+
notFound();
33+
}
34+
35+
const { title, description } = formText[type];
36+
37+
return <SingleCard title={title} description={description}>
38+
<AuthForm name={type}/>
39+
</SingleCard>
40+
}

packages/devextreme-cli/src/templates/nextjs/application/src/app/auth/create-account/page.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/devextreme-cli/src/templates/nextjs/application/src/app/auth/login/page.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/devextreme-cli/src/templates/nextjs/application/src/app/auth/reset-password/page.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/devextreme-cli/src/templates/nextjs/application/src/app/layout.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
'use client'
22

3-
import { useEffect } from 'react';
4-
import { useRouter, usePathname } from 'next/navigation';
3+
import { usePathname } from 'next/navigation';
54
import LoadPanel from 'devextreme-react/load-panel';
65
import { AuthProvider, useAuth} from '../contexts/auth';
76
import { NavigationProvider } from '../contexts/navigation';
87
import { useScreenSizeClass } from '../utils/media-query';
98
import { ThemeContext, useThemeContext} from "../theme";
109

1110
function Page({ children }) {
12-
const { user, loading } = useAuth();
13-
const router = useRouter();
14-
15-
useEffect(() => {
16-
if (!loading && !user) {
17-
router.push('/auth/login');
18-
}
19-
}, [user, loading, router]);
11+
const { loading } = useAuth();
2012

2113
if (loading) {
2214
return <LoadPanel visible={true} />;
@@ -33,7 +25,7 @@ export default function RootLayout({ children }) {
3325
return (
3426
<html lang="en">
3527
<title>NextJs Dx App</title>
36-
<body class="dx-viewport">
28+
<body className="dx-viewport">
3729
<ThemeContext.Provider value={themeContext}>
3830
<AuthProvider>
3931
<NavigationProvider>

packages/devextreme-cli/src/templates/nextjs/application/src/app/pages/layout.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
'use client'
2+
import { useEffect } from 'react';
3+
import { useRouter } from 'next/navigation';
4+
import { useAuth } from '@/contexts/auth';
25
import appInfo from '@/app-info';
36
import { Footer } from '@/components';
47
import { <%=layout%> as SideNavBarLayout } from '@/layouts';
58

69
export default function Content({children}) {
10+
const { user, loading } = useAuth();
11+
const router = useRouter();
12+
13+
useEffect(() => {
14+
if (!loading && !user) {
15+
router.push('/auth/login');
16+
}
17+
}, [user, loading, router]);
18+
719
return (
820
<SideNavBarLayout title={appInfo.title}>
921
{children}

0 commit comments

Comments
 (0)