package com.simperium.client;

import com.simperium.util.AuthUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class AuthResponseHandler {

    private AuthResponseListener mListener;
    private User mUser;

    public AuthResponseHandler(User user, AuthResponseListener listener){
        mUser = user;
        mListener = listener;
    }

    public void onResponse(JSONObject response){

        try {
            mUser.setUserId(response.getString(AuthUtil.USERID_KEY));
            mUser.setAccessToken(response.getString(AuthUtil.ACCESS_TOKEN_KEY));
        } catch(JSONException error){
            mListener.onFailure(mUser, AuthException.defaultException());
            return;
        }

        mUser.setStatus(User.Status.AUTHORIZED);
        mListener.onSuccess(mUser, mUser.getUserId(), mUser.getAccessToken());
    }

    public void onError(AuthException error){
        mListener.onFailure(mUser, error);
    }

}

@@ -65,39 +65,8 @@
 l;%0A%0A
-import org.json.JSONException;%0A
 impo
@@ -125,17 +125,16 @@
 ndler %7B%0A
-%0A
     priv
@@ -266,16 +266,17 @@
 istener)
+ 
 %7B%0A      
@@ -377,25 +377,24 @@
 ponse)%7B%0A
-%0A
         
 try %7B%0A  
@@ -389,42 +389,67 @@
     
-try %7B%0A            mUser.setUserId(
+if (!response.optString(AuthUtil.USERID_KEY).isEmpty() && !
 resp
@@ -445,34 +445,34 @@
 () && !response.
-ge
+op
 tString(AuthUtil
@@ -476,55 +476,119 @@
 til.
-USERID_KEY));%0A            mUser.setAccessToken(
+ACCESS_TOKEN_KEY).isEmpty()) %7B%0A            mListener.onSuccess(mUser, response.optString(AuthUtil.USERID_KEY), 
 resp
@@ -592,18 +592,18 @@
 esponse.
-ge
+op
 tString(
@@ -645,34 +645,13 @@
   %7D 
-catch(JSONException error)
+else 
 %7B%0A  
@@ -734,158 +734,9 @@
     
-    return;%0A        %7D%0A%0A        mUser.setStatus(User.Status.AUTHORIZED);%0A        mListener.onSuccess(mUser, mUser.getUserId(), mUser.getAccessToken());
+%7D
 %0A   
@@ -783,16 +783,17 @@
 n error)
+ 
 %7B%0A      
@@ -835,11 +835,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Remove setting user id and access token from response method in auth response handler