Skip to content

Commit bd4c742

Browse files
committed
feat: update login form to use magic link and add success/error notifications
1 parent 5740581 commit bd4c742

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

web/src/modules/auth/components/client/LoginFrom.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import axios from 'axios';
55
import Link from 'next/link';
66
import { FC, useState } from 'react';
77
import { useForm } from 'react-hook-form';
8+
import { toast } from 'react-hot-toast';
89

910
import { ErrorBalloon } from '@web/src/modules/shared/components/client/ErrorBalloon';
1011

1112
import {
1213
Input,
1314
SubmitButton,
1415
} from '../../../shared/components/client/FormElements';
16+
import ClientAxios from '@web/src/lib/axios/ClientAxios';
1517

1618
type LoginFormData = {
1719
email: string;
@@ -33,23 +35,25 @@ export const LoginForm: FC = () => {
3335
const onSubmit = async ({ email }: LoginFormData) => {
3436
try {
3537
setIsLoading(true);
36-
const url = `${backendURL}/auth/login/email`;
38+
const url = `${backendURL}/auth/login/magic-link`;
3739

38-
const response = await axios.post(
39-
url,
40-
{
41-
destination: email,
42-
},
43-
{
44-
headers: {
45-
'Content-Type': 'application/json',
46-
},
47-
},
48-
);
40+
const response = await ClientAxios.post(url, {
41+
destination: email,
42+
});
4943

5044
console.log(response.data);
45+
46+
toast.success('An email has been sent to you with a login link.', {
47+
position: 'top-center',
48+
duration: 20_000, // 20 seconds
49+
});
50+
51+
toast.success('Please check your inbox and follow the instructions.', {
52+
position: 'top-center',
53+
duration: 20_000, // 20 seconds
54+
});
5155
} catch (error) {
52-
console.error(error);
56+
toast.error('An error occurred. Please try again later.');
5357
} finally {
5458
setIsLoading(false);
5559
}
@@ -91,8 +95,6 @@ export const LoginForm: FC = () => {
9195
/>
9296
</div>
9397

94-
{errors.email && <ErrorBalloon message={errors.email.message} />}
95-
9698
<div className='flex flex-row items-center justify-end gap-8'>
9799
{/* Submit button */}
98100
<SubmitButton isDisabled={isLoading} />

web/src/modules/auth/components/loginPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ export const LoginPage = () => {
100100
/>
101101
<span className='flex-1 text-nowrap'>Log in with Discord</span>
102102
</Link>
103-
<div className='ht-[1px] w-full' />
104-
<hr className='ht-[1px] w-full' />
105-
<div className='ht-[1px] w-full' />
106103
<Link
107104
data-test='login-discord'
108105
href={'/login/email'}

0 commit comments

Comments
 (0)