This is a project to help users find out more about whales and to encourage them to go and spot whales in the wild. This three-week project culminated in a demo and presentation, which can be found here: https://docs.google.com/presentation/d/1bKVYXXJJkqQITtu8VHvW2HF2q71xj8jqyaf7CnvuU-o/edit#slide=id.g302d12489e3_19_0
A database needs to be prepared, and all required dependencies need to be installed, before the project can be successfully run.
First, create a user with the following credentials and permissions:
- Username
whales
- Password
whales
- Able to login
Then, create a database called whales
, owned by the user created previously (also called whales
).
dotnet tool restore
npm install
dotnet restore
dotnet dotnet-ef database update
npm install
To run the project locally, the backend and frontend should be started separately.
dotnet watch run
npm start
Data will be seeded in development.
You can find the seeding data files in the /backend/SeedData
folder.
These files contain the sample data and methods that are called in Program.cs (inside the if (app.Environment.IsDevelopment())
statement) to populate the database accordingly.
After seeding the data, the user table is seeded with the following admin: UserName = "Admin" Email = "[email protected]" Password = "Pa$$word123"
When committing changes a pre-commit hook will run that includes runs a linter and the tests for both frontedn and backend.
If you need to commit without the pre-commit hook running you can used the --no-verify
flag when making your commit
git commit --no-verify -m "your commit message here"
Authorization checks have been added which means all endpoints except /auth/login and /auth/register are protected. To protect other endpoints, add the [Authorize] attribute in the controller.
Protected endpoints will return a 401 Unauthorized response unless you pass the logged-in user's JWT token as a header.
To add the JWT token as a header to fetch requests which access protected endpoints do the following:
In the .tsx file where the fetch request is being called:
- import the login context to access the value of the JWT token
- pass the token as a prop called 'header' in the method which calls the fetch request
In the backendClient.ts file:
- add 'header: string' as a prop to the method
- add "Authorization":
Bearer ${header}
to the list of headers
You should see unlocked padlock icons on the right of every endpoint.
- Run the /auth/login endpoint
- Copy the jwt token returned in the HTTP response
- Click the green Authorize button on the top right of the Swagger page
- In the pop-up, type 'Bearer' + space + paste the token and click Authorize
- Now all the endpoints should show a locked padlock icon
- The jwt header should be passed automatically to all protected endpoints
- If you click the green Authorize button again and click Logout, the jwt token will be lost and you will need to log in again
- Run the /auth/login endpoint
- Copy the jwt token returned in the HTTP response
- When running a protected endpoint, click the Authorization tab
- Select 'Bearer Token' from the Auth Type dropdown list
- Paste the token into the box
- Postman will add the correct header
You can run the app without the API key, but the map will appear in 'development mode', so not all the map features will be functional.
- follow the instructions from this page to get an API key: https://developers.google.com/maps/get-started
- In your project on the Cloud Console, go to 'Map styles' and create a new style (you don't need to change any settings, just save it)
- Once you have saved a map style, you will get a Map style ID
- create a new .env file in the frontend folder, following the .env.template file, and put in your API key and the Map style ID