Skip to content

Commit 416056c

Browse files
committed
πŸ‘šπŸŒš ↝ [ FCDB-24 ] Login modal now working
1 parent 41d3a98 commit 416056c

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { ReactNode, useEffect } from 'react';
2+
// import { useHistory } from 'react-router-dom';
3+
import Link from 'next/link';
4+
import Layout from '../../components/Section/Layout';
5+
import { Auth, ThemeSupa } from '@supabase/auth-ui-react';
6+
import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react';
7+
import { useRouter } from 'next/router';
8+
9+
export function SupabaseAuthWrapper({ children }: { children: ReactNode }) {
10+
return (
11+
<div className='flex min-h-full flex-col justify-center pt-10 sm:px-6 lg:px-8'>
12+
<div className='sm:mx-auto sm:w-full sm:max-w-md'>
13+
<div className='bg-white py-8 px-4 shadow-xl ring-1 ring-gray-900/10 sm:rounded-lg sm:px-10 dark:bg-white dark:text-gray-900'>
14+
<div className='-mt-8'>
15+
{children}
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
);
21+
};
22+
23+
interface AuthPageProps {
24+
children: ReactNode;
25+
}
26+
27+
export function AuthPage({ children }: AuthPageProps) {
28+
// const history = useHistory();
29+
const session = useSession();
30+
const router = useRouter();
31+
32+
// useEffect(() => {
33+
// if (session) {
34+
// router.push('/')
35+
// }
36+
// }, [session, history]);
37+
38+
return (
39+
<SupabaseAuthWrapper>
40+
{children}
41+
</SupabaseAuthWrapper>
42+
);
43+
};
44+
45+
export default function LoginPage() {
46+
const supabase = useSupabaseClient();
47+
48+
return (
49+
<AuthPage>
50+
<Auth supabaseClient={supabase} appearance={{ theme: ThemeSupa }} theme='dark' />
51+
<br />
52+
<span className='text-sm font-medium text-gray-900 dark:text-gray-900'>
53+
Don't have an account yet?{' '}
54+
<Link href='/signup' className='underline'>
55+
go to signup
56+
</Link>
57+
.
58+
</span>
59+
<br />
60+
</AuthPage>
61+
);
62+
};

β€Žpages/login/index.tsx

+48-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useEffect } from 'react';
33
import { useSession, useSupabaseClient } from '@supabase/auth-helpers-react';
44
import { useRouter } from 'next/router'; // Import the useRouter hook
55
import Layout from '../../components/Section/Layout';
6+
import LoginPage from '../../components/Authentication/LoginModal';
67

78
const Login = () => {
89
const session = useSession();
@@ -19,12 +20,56 @@ const Login = () => {
1920
return (
2021
<div className='container' style={{ padding: '50px 0 100px 0' }}>
2122
{!session ? (
22-
<div className='w-80%'><Auth supabaseClient={supabase} appearance={{ theme: ThemeSupa }} theme='dark' /></div>
23+
// <div className='w-80%'><Auth supabaseClient={supabase} appearance={{ theme: ThemeSupa }} theme='dark' /></div>
24+
<div><LoginPage /></div>
2325
) : (
2426
<Layout>Logged in</Layout>
2527
)}
2628
</div>
2729
);
28-
}
30+
};
31+
32+
export default Login;
33+
34+
/*
35+
import { useHistory } from 'react-router-dom';
36+
import { useEffect } from 'react';
37+
import { Link } from 'react-router-dom';
38+
import { LoginForm } from '@wasp/auth/forms/Login';
39+
import { AuthWrapper } from './authWrapper';
40+
import useAuth from '@wasp/auth/useAuth';
41+
42+
export default function Login() {
43+
const history = useHistory();
2944
30-
export default Login;
45+
const { data: user } = useAuth();
46+
47+
useEffect(() => {
48+
if (user) {
49+
history.push('/');
50+
}
51+
}, [user, history]);
52+
53+
return (
54+
<AuthWrapper>
55+
<LoginForm />
56+
<br />
57+
<span className='text-sm font-medium text-gray-900 dark:text-gray-900'>
58+
Don't have an account yet?{' '}
59+
<Link to='/signup' className='underline'>
60+
go to signup
61+
</Link>
62+
.
63+
</span>
64+
<br />
65+
<span className='text-sm font-medium text-gray-900'>
66+
Forgot your password?{' '}
67+
<Link to='/request-password-reset' className='underline'>
68+
reset it
69+
</Link>
70+
.
71+
</span>
72+
</AuthWrapper>
73+
);
74+
}
75+
*/

0 commit comments

Comments
Β (0)