Project#4 Using the JWT gem -Rails Authorization

Using a React frontend and a rails backend.

rails new <backend_project_name> --api -T --database=postgresql
gem 'bcrypt', '~> 3.1.7'
gem 'active_model_serializers'
gem 'jwt'
gem 'rack-cors'
npm install -g create-react-app
create-react-app <frontend_project_name>
npm install react-router-dom

Setup the backend

ActiveModelSerializers.config.default_includes = '**'
  • JWT.encode takes up to three arguments: a payload to encode, a secret, and (optionally) a hashing algorithm. This method returns a JWT as a string.
  • JWT.decode takes up to three arguments: a JWT as a string, a secret, and (optionally) a hashing algorithm.
  • The payload is the data that we want to encode.

Setting Up the Routes and Controllers

In the Application Controller

In the User controller

The FrontEnd

GET, POST, PATCH, DELETE REQUESTS

--

--

--

Copy and Paste what’s on my mind. Perfect.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Gist: Better Than unordered_map

Big Launch Event — Grow With Google — Inauguration Ceremony of Developer Student Clubs — Virtual…

Learn how to use google 101!

Day 7 Hangman game

Creating Migrations and Updating the Schema

How to fix your $GOPATH and $GOROOT

How to write API Automated tests — RestAssured (4/7)

Firefox: yet another chrome clone?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dong Xia

Dong Xia

Copy and Paste what’s on my mind. Perfect.

More from Medium

Reverse Proxy Made Simple with Docker and Nginx

How To Connect To Web3.0 With Nodejs?

Solidity FundMe Contract

Ruby on Rails Version 7.0