Friday exercise - Trip App with Security
Continue the tripapp from frontend react II - codelab
- API to use:
- 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:
npm install react-router-dom@6.28.0
-
Setup the router in
main.jsx
and setup a parent route with the App component as element surrounding all the other routes. Documentation for react router can be found here -
Setup 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
Admin
role) - Trip (to show a single trip with details about guide and packing list (if available) - protected with
User
role)
-
Setup a Header component used inside App (allways visible) with 2 links to
trips
,guides
(andtrip/:id
will 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
Authorization
header when making the request
- Create the Trip Details Component with the
User
role