Trip with Security
API to use:
- GET https://tripapi.cphbusinessapps.dk/api/trips (ANYONE)
- GET https://tripapi.cphbusinessapps.dk/api/guides (ADMIN)
- GET https://tripapi.cphbusinessapps.dk/api/trips/3 (USER)
- GET https://tripapi.cphbusinessapps.dk/api/auth/login (ANYONE)
users in the system:
- user {“username”: “user”, “password”: “user123”} - role: USER
- admin {“username”: “admin”, “password”: “admin123”} - role: ADMIN
Use your solution to the codelab exercise in the second react week.
Install react router in the project
npm i react-routerSetup the router in
main.jsxand setup a parent route with the App component as element surrounding all the other routes. Documentation for react router can be found hereSetup 3 sub routes under the parent route:
- Trips (to show a list of all available trips)
- Guides (to show a list of all available guides - protected with the
Adminrole) - Trip (to show a single trip with details about guide and packing list (if available) - protected with
Userrole)
Setup a Header component used inside App (allways visible) with 2 links to
trips,guides(andtrip/:idwill be shown when clicking a trip)In the header component create a login form so that when logged in the form is replaced with the username of the logged in user
- use the apiFacade class from yesterday to do the login to the server.
Create the Trips Component to show a list of all the trips (use the code you have from the codelab)
Create the Guides Component to show a list of all guides
- Use the apiFacade to send the token with the
Authorizationheader when making the request
- Create the Trip Details Component with the
Userrole