shlogg · Early preview
Ruwhan @ruwhan

Implementing JWT Authentication In Rails API Endpoints

Implementing JWT Auth in Rails: Part 2. Create API endpoint for getting current user, decode token from Authorization header, and eliminate database access for authenticated users.

Overview

In the previous part, we've already covered how to setup, and encode our user object. There are still some parts missing, how do we decode and send the token, and how it will affect our API endpoints to be faster and more efficient.
The functions already there, in app/controllers/concern/Authentication.rb, we already have, decode, current_user, get_token, we gonna use them here.

  
  
  Authenticating the Requests

We will need to create a new endpoint, for the first case, let's create a GET /users/me API endpoint.

rails g controller v1/UsersController

    
    

    
    




It...