W04 Assignment: Authentication and Authorization
Overview
- Purpose: Demonstrate your knowledge of this week's concepts.
- Task: Complete your assigned features and submit the required deliverables.
This week, your team will add authentication-related behavior to the Kizuna Rail project. Authentication changes need careful coordination because they affect routing, environment variables, protected data, frontend behavior, and deployment settings.
Assignment Requirements
- Choose one feature set from the list; each team member completes one feature set.
- Create one or more GitHub issues for your selected feature set.
- Implement the selected feature set, record a walk-through video, and prepare one or more pull requests.
- Share each pull request for your feature set in your Microsoft Teams channel when it is ready for review.
- Upload a reflection document to Canvas.
Feature Sets
Each person must complete one feature set. The feature sets are ordered from most critical to least critical. A five-person team should complete all five feature sets. If your team has fewer than five people, complete the first feature sets in order. Assign and complete Feature Set 1 first because the other feature sets depend on it.
Feature Set 1: Core Authentication
For this feature set you will implement the basic authentication functionality for the application.
Complete this first
All other feature sets this week depend on this functionality, so the person who chooses this work should complete it as quickly as possible.
Even though code reviews will not be submitted to Canvas until the start of next week, because the rest of the work this week depends on this functionality, your team should review and merge this feature set as soon as possible.
Follow the process presented in the Session Authentication Middleware learning activity. In particular, you should complete the following tasks:
- Add a Mongoose schema for users and roles. Users should contain a display name, username, email, password hash, and role.
- Update the db import scripts to add the standard roles to the database. (And run the script to ensure they are present for your team.)
- Create new register and login pages.
- Add the necessary functionality so users can register, log in, and log out, and the logged-in user's information and role are stored in the session.
- Create middleware functions to check for authentication and roles for both pages and APIs as follows:
requireApiLogin(): Return JSON with a 401 error if the user is not authenticated.requirePageLogin(): Redirect to the login page if the user is not authenticated.requireApiRole(role): Return JSON with a 401 error if the user is not authenticated or a 403 error if the user does not have the required role.requirePageRole(role): Redirect to the login page if the user is not authenticated or to a 403 error page if the user does not have the required role.
- Create a new EJS page for an Admin Dashboard. It should require the user to be signed in and have the admin role. For now the page can simply say, "Welcome to the Admin Dashboard".
Feature Set 2: User Dashboard and Navigation
For this feature set, you will add a new user dashboard and additional navigation links throughout the application to improve user experience and accessibility.
- Create a new dashboard page for a standard user that shows the following:
- Welcome message with the user's display name.
- List of all bookings where their email matches one of the passengers. This list should be hydrated dynamically through a client-side JavaScript call to the API.
- Link to the booking admin page.
- Link to the user admin page.
- Update the header to include links to register and login. These links should only be visible to users who are not currently signed in.
- Update the header to include a link to logout. This link should only be visible to users who are currently signed in.
- Update the header to include a link to the dashboard. This link should only be visible to users who are currently signed in. If the user is an admin, the link should point to the admin dashboard. Otherwise, it should point to the standard user dashboard.
- Update the login process so that admin users are automatically redirected to the admin dashboard after logging in. All other users should be redirected to the standard user dashboard.
Feature Set 3: Protected User Admin Page
For this feature set, you will create a new user admin page that requires authentication and provides the ability to update and delete users.
- Create a new user admin page that requires authentication.
- If the user is not authenticated, redirect them to the login page.
- If the user is authenticated and has the admin role, they should see all users in the system.
- If the user is authenticated but does not have the admin role, they should see their own user information.
- The list of users should be added dynamically through a client-side JavaScript call to the API.
- Add to this page the ability to update and delete users through the API.
- After updating or deleting a user, the list should be updated (without requiring a page refresh) to show the updated information.
- You should create the model, controller, and route functions for the update and delete operations.
- Make sure the routes are properly secured and only allow authorized users to perform these actions. (Any user can update or delete their own information. Admin users can update or delete any user.)
- Update the admin dashboard to include a link to the protected user admin page.
Feature Set 4: Protected Booking Admin Page
For this feature set, you will update the booking admin page to require authentication and provide the ability to update and delete bookings.
- Update the booking admin page to require authentication.
- If the user is not authenticated, redirect them to the login page.
- If the user is authenticated and has the admin role, they should see all bookings in the system.
- If the user is authenticated but does not have the admin role, they should see all bookings where their email address matches one of the passengers.
- The list of bookings should be added dynamically through a client-side JavaScript call to the API. (This should have been completed in the previous week.)
- Add to this page the ability to update and delete bookings through the API.
- After updating or deleting a booking, the list should be updated (without requiring a page refresh) to show the updated information.
- You should create the model, controller, and route functions for the update and delete operations.
- Make sure the routes are properly secured and only allow authorized users to perform these actions. (Any user can update or delete bookings where they are a passenger. Admin users can update or delete any booking.)
- Update the admin dashboard to include a link to the protected booking admin page.
Feature Set 5: Protected Trip Admin Page
For this feature set, you will create a new trip admin page that requires the admin role and provides the ability to update and delete trips.
- Implement a new trip admin page that requires authentication.
- If the user is not authenticated, redirect them to the login page.
- If the user does not have the admin role, they should be redirected to a 403 error page.
- If the user is authenticated and has the admin role, they should see all trips in the system.
- The list of trips should be added dynamically through a client-side JavaScript call to the API. (This should have been completed in the previous week.)
- Add to this page the ability to update and delete trips through the API.
- After updating or deleting a trip, the list should be updated (without requiring a page refresh) to show the updated information.
- You should create the model, controller, and route functions for the update and delete operations.
- Make sure the routes are properly secured and only allow admin users to perform these actions.
- When editing a trip, the user should be able to select new stations or new schedules from existing options, but you do not need to implement the creation of new stations or schedules.
- Update the admin dashboard to include a link to the protected trip admin page.
Workflow
Select and coordinate feature sets
- Complete the Week 04 Team Activity.
- Make sure every required feature set has an owner.
- Ensure Feature Set 1: Core Authentication is assigned and completed first because the other feature sets depend on it.
- Post the feature-set owners and dependencies in your Microsoft Teams channel so everyone knows who is responsible for each piece of work.
Develop a spec for your feature set
Write a detailed spec before coding. You may use one spec for the whole feature set or separate specs for its smaller pieces, but the spec must be detailed enough for a teammate to understand and review the planned work.
- An overall description of the feature set.
- The data model, session data, roles, or collections involved.
- The page routes and API endpoints, including request and response formats and status codes.
- What signed-out, signed-in, and unauthorized users should experience.
- A test plan with specific checks.
Create GitHub issues
Create at least one GitHub issue for your feature set. Include the relevant information from your spec in the issue description. If the feature set has independent pieces, create separate issues so each pull request has a clear and reviewable purpose.
Implement the feature set
Use AI to help
You are encouraged to use AI to help write code for your feature set. Work through files and decisions individually rather than asking AI to change the entire project at once. You need to understand the code you contribute, and AI output still needs to be checked against the assignment requirements and your team's existing patterns.
Follow these steps for each issue in your feature set:
- Create a branch for the issue.
- Implement the work.
- Test the change locally, including signed-out, signed-in, and unauthorized behavior when it applies.
- Run the ESLint check and correct any reported errors before creating the pull request.
- Create a walk-through video that shows the feature working locally, explains the key code, and describes at least one technical decision you made.
- Open a pull request that connects to the GitHub issue, summarizes the changes, includes verified test-plan steps, and links to the walk-through video.
- Post in your Microsoft Teams channel that the pull request is ready for review.
- Repeat for any additional issues in your feature set.
Pull requests are required
Each assigned feature set must be completed through at least one pull request. Create additional pull requests when they make the work safer and easier to review. Do not push code directly to main.
Prepare for code review
Your teammates will review these pull requests as they become available and during the next week. Make every pull request ready for review before the end of this assignment.
- The pull request connects to its GitHub issue.
- The description explains what changed.
- The description includes clear testing notes.
- The pull request includes a link to the walk-through video.
- The pull request is posted in Microsoft Teams as ready for review.
Complete the reflection
- Download the Week 04 reflection template.
- Answer the questions in your own words.
- Upload the completed reflection document to Canvas.
Deliverables Checklist
- Your team coordinated the required feature-set owners.
- You completed your selected feature set.
- You created one or more GitHub issues and pull requests for that feature set.
- You shared your pull requests in Microsoft Teams when they were ready for review.
- You tested the relevant signed-out, signed-in, and authorization behavior.
- You uploaded your reflection document to Canvas.
Other Links:
- Return to: Week Overview | Course Home