Ruby on Rails 6 course as API showing authentication via devise_token_auth.
This repository is part of the Ruby on Rails 6 - Autenticação via API on YouTube.
Ruby version | 3.0.3 |
Rails version | 6.1.5 |
Database | PostgreSQL |
git clone https://github.com/peimelo/blog_api.git
cd blog_api
# installation of dependencies
bundle install
# creation of database and tables
rails db:create
rails db:migrate
rails db:migrate RAILS_ENV=test
# run the project
rails s
The backend is available at http://localhost:3000
.
# delete the config/credentials.yml.enc file
rm config/credentials.yml.enc
# run the command to create credentials and master key (replace 'code' if you don't use VS Code)
EDITOR="code --wait" bin/rails credentials:edit
Add the information below in the credentials to configure the email used by the Devise gem (replace with the values you want):
# ... your content above
gmail:
user_name: your@email.com
password: your_password
exception_recipients: exceptions@example.com
Save and close the config/credentials.yml.enc
file.
If you want to use another email provider, change it in the file
config/environments/production.rb
.
To configure default_confirm_success_url
, change it in the file
config/initializers/devise_token_auth.rb
.
To configure CORS origins
, change it in the file
config/initializers/cors.rb
.
To configure Exception Notification, change it in the file
config/initializers/exception_notification.rb
.
To run the tests:
bundle exec rspec
If you want to import the requests into Insomnia, use the file Insomnia.json
at the root of this project.
It will be necessary to install the plugin insomnia-plugin-dotenv.
Create an environment variable file at the root of the project to add sensitive data:
touch .env.development
Add the contents below to the file above:
password=your-password
access-token=your-access-token
client=your-client
In Insomnia, go to Manage Environments
and set the envFilePath
value to the file path .env.development
:
{
// ... your code above
"envFilePath": "/path/to/file/your_repo/.env.development"
}
Any .env.*
file is being ignored by this project's GIT.