Skip to content

Commit

Permalink
fix naming to handleSignIn, handleSignUp, rename password field in re…
Browse files Browse the repository at this point in the history
…set-password
  • Loading branch information
ccatherinetan committed Oct 12, 2023
1 parent 5b00d39 commit 8e1dc74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Login() {
push('/');
};

const signInWithEmail = async () => {
const handleSignIn = async () => {
const { error } = await supabase.auth.signInWithPassword({
email,
password,
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function Login() {
<button type="button" onClick={handleSignUp}>
Sign up
</button>
<button type="button" onClick={signInWithEmail}>
<button type="button" onClick={handleSignIn}>
Sign in
</button>
</>
Expand Down
9 changes: 6 additions & 3 deletions src/app/reset-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { useRouter } from 'next/navigation';
import supabase from '../../api/supabase/createClient';

export default function ResetPassword() {
const [newPassword, setPassword] = useState('');
const [password, setPassword] = useState('');
const { push } = useRouter();
const resetPassword = async () => {
await supabase.auth.updateUser({ password: newPassword });
const { error } = await supabase.auth.updateUser({ password });
if (error) {
throw new Error(`An error occurred trying to sign in: ${error}`);
}
push('/login');
};

Expand All @@ -18,7 +21,7 @@ export default function ResetPassword() {
type="password"
name="password"
onChange={e => setPassword(e.target.value)}
value={newPassword}
value={password}
/>
<button type="button" onClick={resetPassword}>
Reset Password
Expand Down
9 changes: 2 additions & 7 deletions src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import supabase from '../../api/supabase/createClient';

export default function Settings() {
const { push } = useRouter();
const signOut = async () => {
const handleSignOut = async () => {
const { error } = await supabase.auth.signOut();
if (error) {
throw new Error(`An error occurred trying to sign out: ${error}`);
Expand All @@ -18,7 +18,7 @@ export default function Settings() {

return (
<>
<button type="button" onClick={signOut}>
<button type="button" onClick={handleSignOut}>
Sign out
</button>
<button type="button" onClick={resetPassword}>
Expand All @@ -27,8 +27,3 @@ export default function Settings() {
</>
);
}

/*
Send email for password reset using .resetPasswordForEmail while providing a redirectTo parameter
Email link will work as a magic link and log the user in then take them to the url specified in the redirectTo parameter
Create form to update the password and call the .updateUser method with the new password */

0 comments on commit 8e1dc74

Please sign in to comment.