Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Create a textinput component (old) #39

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
088ed77
Created AuthContext with useAuth hook to manage user authentication
rachaelch3n Oct 23, 2024
0d4d431
wrap app with AuthProvider and introduce AuthUser interface
rachaelch3n Oct 26, 2024
d6f162a
separated login and signup pages
rachaelch3n Oct 30, 2024
594ad58
fixed type errors on authcontext
rachaelch3n Nov 3, 2024
3a7501c
Update pnpm-lock.yaml after installing dependencies
rachaelch3n Nov 3, 2024
e578a4d
removed loading from dependancy array to get rid of flickering in das…
rachaelch3n Nov 4, 2024
958de99
move AuthProvider wrapper to app/layout
ccatherinetan Nov 8, 2024
1beb0f8
prettier fix
ccatherinetan Nov 8, 2024
2ebc739
Created AuthContext with useAuth hook to manage user authentication
rachaelch3n Oct 23, 2024
08f643b
wrap app with AuthProvider and introduce AuthUser interface
rachaelch3n Oct 26, 2024
8cc88b8
separated login and signup pages
rachaelch3n Oct 30, 2024
888b139
fixed type errors on authcontext
rachaelch3n Nov 3, 2024
3913df3
removed loading from dependancy array to get rid of flickering in das…
rachaelch3n Nov 4, 2024
40f3df7
added confirm password inp
rachaelch3n Nov 4, 2024
c78c1e0
ran prettier
rachaelch3n Nov 4, 2024
e4baf7b
ensured signup button is disabled without email input
rachaelch3n Nov 4, 2024
a196dce
added textinput component and styled login and signup pages
rachaelch3n Nov 13, 2024
ce86c0a
updated colors to match figma design
rachaelch3n Nov 13, 2024
4b9e4d9
fixed import pathway
rachaelch3n Nov 18, 2024
3745a37
logic of signup and login with blank text inputs
rachaelch3n Dec 6, 2024
60a765e
finished auth styling mostly
rachaelch3n Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 77 additions & 27 deletions app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,96 @@

import { useState } from 'react';
import { useRouter } from 'next/navigation';
import TextInput from '@/components/TextInput';
import { StyledButton, TextErrorWrapper } from '@/components/TextInput/styles';
import COLORS from '@/styles/colors';
import { H2 } from '@/styles/text';
import { useAuth } from '../../../utils/AuthProvider';

export default function Login() {
const { signIn } = useAuth(); // Use `signIn` function from AuthProvider
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const router = useRouter();
const [showPassword, setShowPassword] = useState(false);
const [invalidEmailError, setInvalidEmailError] = useState('');
const [invalidPasswordError, setInvalidPasswordError] = useState('');

const isFormValid = email && password;

const { push } = useRouter();
const handleLogin = async () => {
// Define handleLogin
try {
await signIn(email, password);
router.push('/'); // Redirect to the home page on success
} catch (error) {
if (error instanceof Error) {
console.error('Login Error:', error.message);
const { error } = await signIn(email, password);
push('/');

if (error) {
// Match error messages from Supabase
if (error.message.includes('Invalid login credentials')) {
setInvalidEmailError('Invalid email address');
setInvalidPasswordError('Invalid password');
}
return;
}

// Clear errors on success
setInvalidEmailError('');
setInvalidPasswordError('');
} catch (err) {
console.error('Login Error:', err);
setInvalidEmailError('An unexpected error occurred. Please try again.');
}
};

return (
<>
<input
name="email"
onChange={e => setEmail(e.target.value)}
value={email}
placeholder="Email"
/>
{/* Email input*/}
<input
type="password"
name="password"
onChange={e => setPassword(e.target.value)}
value={password}
placeholder="Password"
/>
<button type="button" onClick={handleLogin}>
Sign in
</button>{' '}
{/* Sign in button */}
</>
<form
onSubmit={handleLogin}
style={{
backgroundColor: COLORS.whitegray,
minHeight: '100vh',
padding: '1.25rem',
}}
>
<div style={{ display: 'flex', flexDirection: 'column', gap: '1.5rem' }}>
<H2 style={{ color: COLORS.shrub }}>Log In</H2>
<TextErrorWrapper>
<TextInput
id="email-input"
type="email"
label="Email"
onChange={setEmail}
value={email}
error={!!invalidEmailError}
/>
{/* Email input*/}
<p style={{ color: COLORS.error, marginTop: '0' }}>
{invalidEmailError}
</p>
</TextErrorWrapper>
<TextErrorWrapper>
<TextInput
id="password-input"
label="Password"
type="password"
onChange={setPassword}
value={password}
isVisible={showPassword}
toggleVisibility={() => setShowPassword(!showPassword)}
error={!!invalidPasswordError}
/>
<p style={{ color: COLORS.error, marginTop: '0' }}>
{invalidPasswordError}
</p>
{/* Password input*/}
</TextErrorWrapper>
<StyledButton
type="button"
onClick={handleLogin}
disabled={!isFormValid}
>
Log in
</StyledButton>{' '}
{/* Sign in button */}
</div>
</form>
);
}
Loading
Loading