Browse Source

Ajout du username dans la réponse de l'API lors de l'obtention d'un token

Lou 3 years ago
parent
commit
d6b8083ea4

+ 2
- 1
app/controllers/api/v1/tokens_controller.rb View File

4
     if @user&.authenticate(user_params[:password])
4
     if @user&.authenticate(user_params[:password])
5
       render json: {
5
       render json: {
6
         token: JsonWebToken.encode(user_id: @user.id),
6
         token: JsonWebToken.encode(user_id: @user.id),
7
-        email: @user.email
7
+        email: @user.email,
8
+        username: @user.username
8
       }
9
       }
9
     else
10
     else
10
       head :unauthorized
11
       head :unauthorized

+ 2
- 0
test/controllers/api/v1/tokens_controller_test.rb View File

11
 
11
 
12
     json_response = JSON.parse(response.body)
12
     json_response = JSON.parse(response.body)
13
     assert_not_nil json_response['token']
13
     assert_not_nil json_response['token']
14
+    assert_not_nil json_response['email']
15
+    assert_not_nil json_response['username']
14
   end
16
   end
15
 
17
 
16
   test 'should not get JWT token' do
18
   test 'should not get JWT token' do

Loading…
Cancel
Save