-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAPIFetcher.js
40 lines (30 loc) · 945 Bytes
/
APIFetcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, { useEffect } from "react";
function APIFetcher(props) {
// register user
// if successful, authenticate user
// if get jwt log user in
useEffect(() => {
if (props.APIDetails.user.length > 0) {
let formData = new FormData()
formData.append('user', props.APIDetails.user)
formData.append('email', props.APIDetails.email)
formData.append('pass', props.APIDetails.pass)
const url = myCustomScript.php
fetch(url, {
method: 'POST',
body: formData
})
.then((response)=>response.text())
.then((post)=> {
console.log(post)
// if post is jwt use it to authenticate
// if not, throw err
})
}
}, [props.APIDetails])
return (
<>
</>
)
}
export default APIFetcher