Chore: Render avatar url in validate token method (#448)
This commit is contained in:
parent
6325acd183
commit
199642d3bd
7 changed files with 59 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
|||
class ConfirmationsController < Devise::ConfirmationsController
|
||||
class Devise::ConfirmationsController < Devise::ConfirmationsController
|
||||
skip_before_action :require_no_authentication, raise: false
|
||||
skip_before_action :authenticate_user!, raise: false
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
class PasswordsController < Devise::PasswordsController
|
||||
class Devise::PasswordsController < Devise::PasswordsController
|
||||
include AuthHelper
|
||||
|
||||
skip_before_action :require_no_authentication, raise: false
|
|
@ -1,4 +1,4 @@
|
|||
class SessionsController < ::DeviseTokenAuth::SessionsController
|
||||
class Devise::SessionsController < ::DeviseTokenAuth::SessionsController
|
||||
# Prevent session parameter from being passed
|
||||
# Unpermitted parameter: session
|
||||
wrap_parameters format: []
|
10
app/controllers/devise/token_validations_controller.rb
Normal file
10
app/controllers/devise/token_validations_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class Devise::TokenValidationsController < ::DeviseTokenAuth::TokenValidationsController
|
||||
def validate_token
|
||||
# @resource will have been set by set_user_by_token concern
|
||||
if @resource
|
||||
render 'devise/token.json'
|
||||
else
|
||||
render_validate_token_error
|
||||
end
|
||||
end
|
||||
end
|
17
app/views/devise/token.json.jbuilder
Normal file
17
app/views/devise/token.json.jbuilder
Normal file
|
@ -0,0 +1,17 @@
|
|||
json.payload do
|
||||
json.success true
|
||||
json.data do
|
||||
json.id @resource.id
|
||||
json.provider @resource.provider
|
||||
json.uid @resource.uid
|
||||
json.name @resource.name
|
||||
json.nickname @resource.nickname
|
||||
json.email @resource.email
|
||||
json.account_id @resource.account_id
|
||||
json.pubsub_token @resource.pubsub_token
|
||||
json.role @resource.role
|
||||
json.inviter_id @resource.inviter_id
|
||||
json.confirmed @resource.confirmed?
|
||||
json.avatar_url @resource.avatar_url
|
||||
end
|
||||
end
|
|
@ -1,8 +1,9 @@
|
|||
Rails.application.routes.draw do
|
||||
# AUTH STARTS
|
||||
match 'auth/:provider/callback', to: 'home#callback', via: [:get, :post]
|
||||
mount_devise_token_auth_for 'User', at: 'auth', controllers: { confirmations: 'confirmations', passwords: 'passwords',
|
||||
sessions: 'sessions' }, via: [:get, :post]
|
||||
mount_devise_token_auth_for 'User', at: 'auth', controllers: { confirmations: 'devise/confirmations', passwords: 'devise/passwords',
|
||||
sessions: 'devise/sessions',
|
||||
token_validations: 'devise/token_validations' }, via: [:get, :post]
|
||||
|
||||
root to: 'dashboard#index'
|
||||
|
||||
|
|
26
spec/controllers/devise/token_validations_controller_spec.rb
Normal file
26
spec/controllers/devise/token_validations_controller_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Token Validation API', type: :request do
|
||||
describe 'GET /validate_token' do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
context 'when it is an invalid token' do
|
||||
it 'returns unauthorized' do
|
||||
get '/auth/validate_token'
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is a valid token' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
it 'returns all the labels for the conversation' do
|
||||
get '/auth/validate_token',
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include('payload')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue