@@ -5,13 +5,15 @@ import axios from 'axios';
5
5
import Link from 'next/link' ;
6
6
import { FC , useState } from 'react' ;
7
7
import { useForm } from 'react-hook-form' ;
8
+ import { toast } from 'react-hot-toast' ;
8
9
9
10
import { ErrorBalloon } from '@web/src/modules/shared/components/client/ErrorBalloon' ;
10
11
11
12
import {
12
13
Input ,
13
14
SubmitButton ,
14
15
} from '../../../shared/components/client/FormElements' ;
16
+ import ClientAxios from '@web/src/lib/axios/ClientAxios' ;
15
17
16
18
type LoginFormData = {
17
19
email : string ;
@@ -33,23 +35,25 @@ export const LoginForm: FC = () => {
33
35
const onSubmit = async ( { email } : LoginFormData ) => {
34
36
try {
35
37
setIsLoading ( true ) ;
36
- const url = `${ backendURL } /auth/login/email ` ;
38
+ const url = `${ backendURL } /auth/login/magic-link ` ;
37
39
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
+ } ) ;
49
43
50
44
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
+ } ) ;
51
55
} catch ( error ) {
52
- console . error ( error ) ;
56
+ toast . error ( 'An error occurred. Please try again later.' ) ;
53
57
} finally {
54
58
setIsLoading ( false ) ;
55
59
}
@@ -91,8 +95,6 @@ export const LoginForm: FC = () => {
91
95
/>
92
96
</ div >
93
97
94
- { errors . email && < ErrorBalloon message = { errors . email . message } /> }
95
-
96
98
< div className = 'flex flex-row items-center justify-end gap-8' >
97
99
{ /* Submit button */ }
98
100
< SubmitButton isDisabled = { isLoading } />
0 commit comments