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] User Auth: Created a simple login page that supports sign up and sign in. #5

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from 2 commits
Commits
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
56 changes: 56 additions & 0 deletions app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use client';

import { useState } from 'react';
import supabase from '../../../api/supabase/createClient';

export default function Login() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSignUp = async () => {
const { data, error } = await supabase.auth.signUp({
email,
password,
});

if (error) {
throw new Error(`An error occurred trying to sign up: ${error}`);
}

return data;
};

const signInWithEmail = async () => {
ccatherinetan marked this conversation as resolved.
Show resolved Hide resolved
const { data, error } = await supabase.auth.signInWithPassword({
email,
password,
});

if (error) {
throw new Error(`An error occurred trying to sign in: ${error}`);
}

return data;
};

return (
<>
<input
name="email"
onChange={e => setEmail(e.target.value)}
value={email}
/>
<input
type="password"
name="password"
onChange={e => setPassword(e.target.value)}
value={password}
/>
<button type="button" onClick={handleSignUp}>
Sign up
</button>
<button type="button" onClick={signInWithEmail}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, maybe could put some identifier for where the email goes and where the password goes for signup/login

Copy link
Collaborator

@ccatherinetan ccatherinetan Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! maybe consider creating a placeholder for each of the text inputs
e.g. https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder
<input placeholder="Email" /> and <input placeholder="Password" />

Sign in
</button>
</>
);
}