-
devise: a library in the Ruby on Rails framework that quickly adds user authentication with features like user registration, login, password reset, and etc.
-
authorization: a process that determines if a user permission to perform a specific action within an application or database.
-
authentication: a process that verifies the identity of a user, usually through a username and password.
-
user session: a temporary state that allows a user to interact with a web application. It starts when the user logs in and ends when they log out or after a period of inactivity.
-
JSON Web Token (JWT): a system used for authentication and authorization to allow data to be securely shared about a user between separate applications. A JWT consists of three parts: a header, a payload, and a signature. The header contains information about how the JWT is encoded. The payload contains information about the user. The signature is used to check if the JWT has been tampered with during transmission.
-
localStorage: a feature in web browsers that allows web applications to store small amounts of data on the user's computer like items in a shopping cart or JWTs on active user session.
just making the initial commit on main branch
- Create empty github repo
- create a team on github classroom
- refresh to get empty github repo (no cloning)
-
Create Rails App
apartment_app_backend
and ask for branch protection -
Add the appropriate ruby gems for rspec testing configuration
- If adding directly to Gemfile, then run $
bundle
to add appropriate dependencies for the gems
-
Start server to ensure that the rails app was built correctly
-
Add the appropriate ruby gems for devise to create a User model
- Update the schema
- If received error message, $
rails db:drop, rails db:create, rails db:migrate
- If received error message, $
- Add the appropriate ruby gems for jwt and cors
- Disable authenticity token
- Add cors.rb file to config/initializers
-
Generate resource to add model, controller, routes for Apartment NOTE: User will have many apartments; Apartment will belong to a user, which means it will need a foreign key
-
Establish relationships for User and Apartment models
-
Update the schema
-
Create seeds
- Create users NOTE: This code---> user1 = User.where(email: '[email protected]').first_or_create(password: 'password', password_confirmation: 'password') <---attempts to find a user with the email '[email protected]'. If it finds a user with that email, it will return the existing user and won't change the password. If it doesn't find a user with that email, it will create a new user with the specified email, password, and password confirmation ('password').
- Create apartments
- Create a method that will save new instances to the database that are associated with each user and print out a confirmation that the instance was created
-
Populate database with mock data from seed file
-
Follow the file path as designated in the syllabus to modify the config directory
-
Generate devise users sessions and registrations controllers to manage the tokens
-
Modify the devise routes
-
Create a JWT token NOTE: alternative way to save jwt key ---> Store the token in a variable, Close the application (VS Code), Should see confirmation ---> File encrypted and saved.
to the Gemfile to allow our devise and jwt setup: rack-cors, devise, devise-jwt, dotenv-rails -
Generate jwt_denylist model to store the revoked JWT tokens NOTE: Be mindful of the singular snake_case naming conventions for the model and change method.
-
Update schema
-
Modify the User model to reflect this revocation strategy
-
Exclude
.DS_Store
from version control NOTE: .DS_Store is a file that is automatically generated by the mac operating system. The name stands for "Desktop Services Store." They can become visible when interacting with the GUI on Finder and CLI on Git. To exclude .DS_Store files from being included in a Git repository, you can add the following line to your .gitignore file: .DS_Store -
Connect the two repos with the git remote code from the empty github repo
-
Perform initial commit
-
Ask for branch protection on main branch
-
Stub API endpoints in app/controllers/apartments_controller.rb
-
Create tests in request spec file in spec/requests/apartments_spec.rb
-
See it fail: $
rspec spec/requests/apartments_spec.rb
-
Add logic in the API endpoint to make the test pass
-
See it pass
-
Creates tests in model spec file
-
See it fail
-
Add validation helpers in the model file
-
See it pass
- Create tests in request spec file in spec/requests/apartments_spec.rb that are missing attributes
- Make sure to provide a user for each apartment
- When providing the apartment params for testing, assign a foreign key
apartment_params = {
apartment: {
street: '124 Conch St',
unit: 'A',
city: 'Bikini Bottom',
state: 'CA',
square_footage: 3000,
price: '4000',
bedrooms: 2,
bathrooms: 2,
pets: 'no',
image: 'https://images.unsplash.com/photo-1680842350641-d49b43d71025?auto=format&fit=crop&q=60&w=500&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTN8fHNwb25nZWJvYnxlbnwwfHwwfHx8MA%3D%3D',
user_id: user.id
}
}
- When providing the strong params, allow assignment of a foreign key
private
def apartment_params
params.require(:apartment).permit(:street, :unit, :city, :state, :square_footage, :price, :bedrooms, :bathrooms, :pets, :image, :user_id)
end
- $
git rm -rf --cached coverage