mirror of
https://github.com/ditkrg/AuthorizationServerDemos.git
synced 2026-01-23 05:27:07 +00:00
the react client now automatically fetches data
This commit is contained in:
parent
7fd435a217
commit
354c8260a1
@ -3,6 +3,7 @@ import { signoutRedirect } from '../services/userService'
|
||||
import { useSelector } from 'react-redux'
|
||||
import * as apiService from '../services/apiService'
|
||||
import { prettifyJson } from '../utils/jsonUtils'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
function Home() {
|
||||
const user = useSelector(state => state.auth.user)
|
||||
@ -11,6 +12,10 @@ function Home() {
|
||||
const [color, setColor] = useState('White')
|
||||
const [type, setType] = useState(1)
|
||||
|
||||
useEffect(() => {
|
||||
getVehicles();
|
||||
}, []);
|
||||
|
||||
const [vehicleData, setVehicleData] = useState(null)
|
||||
function signOut() {
|
||||
signoutRedirect()
|
||||
@ -78,7 +83,7 @@ function Home() {
|
||||
{
|
||||
vehicleData ?
|
||||
<ul>
|
||||
{ vehicleData.map(v => (<li>{v.color} {v.model} ({v.licensePlate}) - {getType(v.type)}</li>)) }
|
||||
{ vehicleData.map(v => (<li key={v.id}>{v.color} {v.model} ({v.licensePlate}) - {getType(v.type)}</li>)) }
|
||||
</ul>
|
||||
:
|
||||
<p>No vehicles yet :(</p>
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import axios from 'axios'
|
||||
|
||||
async function getVehiclesFromApi(access_token) {
|
||||
const response = await axios.get(`https://localhost:5001/api/Vehicles`, { headers: { 'Authorization': `Bearer ${access_token}` } });
|
||||
const response = await axios.get(`https://localhost:6001/api/Vehicles`, { headers: { 'Authorization': `Bearer ${access_token}` } });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async function registerVehicle(vehicle, access_token) {
|
||||
console.log(vehicle);
|
||||
const response = await axios.post(`https://localhost:5001/api/Vehicles`, vehicle, { headers: { 'Authorization': `Bearer ${access_token}` } });
|
||||
const response = await axios.post(`https://localhost:6001/api/Vehicles`, vehicle, { headers: { 'Authorization': `Bearer ${access_token}` } });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user