1
1
"use client" ;
2
- import { ChangeEvent , useState } from "react" ;
2
+ import { ChangeEvent , FormEvent , useState } from "react" ;
3
3
import { getMailValidation } from "@/helpers/validators" ;
4
4
import Input from "@/components/Inputs/TextInput" ;
5
+ import { signUp , signUpApi } from "@/lib/strapi/auth" ;
6
+ import { signIn , useSession } from "next-auth/react" ;
5
7
6
8
type RegistrationFormData = {
7
9
username : string ;
@@ -13,6 +15,7 @@ type RegistrationFormData = {
13
15
} ;
14
16
15
17
export default function Registration ( ) {
18
+ const { data : session } = useSession ( ) ;
16
19
const [ formData , setFormData ] = useState < RegistrationFormData > ( {
17
20
username : "" ,
18
21
firstname : "" ,
@@ -22,6 +25,8 @@ export default function Registration() {
22
25
passwordConfirm : "" ,
23
26
} ) ;
24
27
28
+ const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
29
+
25
30
const handleInputChange = ( e : ChangeEvent < HTMLInputElement > ) => {
26
31
const { name, value } = e . target ;
27
32
setFormData ( prevFormData => ( { ...prevFormData , [ name ] : value } ) ) ;
@@ -36,12 +41,28 @@ export default function Registration() {
36
41
< div >
37
42
< h1 className = "h3" > My Account</ h1 >
38
43
< div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-8" >
39
- < form className = "flex flex-col items-stretch gap-4" >
44
+ < form
45
+ className = "flex flex-col items-stretch gap-4"
46
+ onSubmit = { async ( e : FormEvent < HTMLFormElement > ) => {
47
+ e . preventDefault ( ) ;
48
+ console . log ( "submit" ) ;
49
+ console . log ( "err" ) ;
50
+ const registerresp = await signUp ( formData . username , formData . email , formData . password ) ;
51
+ if ( registerresp . error ) {
52
+ console . log ( registerresp . error . message ) ;
53
+ setErrorMessage ( registerresp . error . message ) ;
54
+ return ;
55
+ }
56
+ console . log ( registerresp ) ;
57
+ const res = await signIn ( "credentials" , { email : formData . email , password : formData . password , redirect : false } ) ;
58
+ console . log ( res ) ;
59
+ } }
60
+ >
40
61
< Input type = "text" label = "Username" name = "username" id = "username" value = { formData . username } onChange = { handleInputChange } required />
41
- < div className = "grid grid-cols-1 xl:grid-cols-2 xl:gap-3" >
62
+ { /* <div className="grid grid-cols-1 xl:grid-cols-2 xl:gap-3">
42
63
<Input type="text" label="First Name" name="firstname" id="firstname" value={formData.firstname} onChange={handleInputChange} required />
43
64
<Input type="text" label="Last Name" name="lastname" id="lastname" value={formData.lastname} onChange={handleInputChange} required />
44
- </ div >
65
+ </div> */ }
45
66
< Input
46
67
type = "text"
47
68
label = "Email Address"
@@ -66,8 +87,9 @@ export default function Registration() {
66
87
< input className = "btn ml-auto hover:cursor-pointer" type = "submit" value = "Register" />
67
88
</ form >
68
89
< div >
90
+ { errorMessage != "" && < h2 className = "text-secondary" > { errorMessage } </ h2 > }
69
91
< h2 className = "text-secondary" > Please note</ h2 >
70
-
92
+ { session ?. user && < h2 className = "text-secondary" > { session . user . name } </ h2 > }
71
93
< p >
72
94
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel est adipisci quas, aperiam voluptas, omnis tempora blanditiis quae fuga eum ullam
73
95
commodi a perspiciatis provident pariatur sunt excepturi doloremque! Commodi!
0 commit comments