Fix Missing Auth Header + Typo

This commit is contained in:
sebastian 2024-11-10 18:42:19 +01:00
parent ff80db973c
commit 0d9002776c
4 changed files with 13 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package core.notevault.sync;
import android.content.Context;
import android.content.SharedPreferences;
import core.notevault.sync.auth.AuthInterceptor;
import core.notevault.sync.auth.TokenManager;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
@ -16,9 +17,9 @@ public class ApiClient {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
SharedPreferences sharedPreferences = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
TokenManager tokenManager = new TokenManager(context);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new AuthInterceptor(sharedPreferences))
.addInterceptor(new AuthInterceptor(tokenManager))
.addInterceptor(loggingInterceptor)
.build();

View File

@ -105,7 +105,7 @@ public class SyncWorker extends Worker{
Log.d("SyncWorker", "Process SyncResponse");
//Assign local Concert entries the provided Server ID
List<SyncResponse> syncResponses = new ArrayList<>();
for(SyncCreateResponse createResponse : syncResponse.getCreateResonses()) {
for(SyncCreateResponse createResponse : syncResponse.getCreateResponses()) {
database.updateConcertServerUUID(createResponse.getServerObjectUUID(), createResponse.getDeviceSpecificObjectID());
syncResponses.add(new SyncResponse(createResponse.getServerObjectUUID(), SyncAction.TOBEUPLOADED, SyncObject.CONCERT));
}

View File

@ -10,22 +10,17 @@ import okhttp3.Response;
import java.io.IOException;
public class AuthInterceptor implements Interceptor {
private SharedPreferences sharedPreferences;
private TokenManager tokenManager;
public AuthInterceptor(SharedPreferences sharedPreferences) {
this.sharedPreferences = sharedPreferences;
String token = sharedPreferences.getString("jwt_token", null);
public AuthInterceptor(TokenManager tokenManager) {
this.tokenManager = tokenManager;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
if(originalRequest.url().encodedPath().equals("/api/v1/auth/login")) {
return chain.proceed(originalRequest);
}
String token = sharedPreferences.getString("jwt_token", null);
String token = tokenManager.getToken();
if (token == null) {
return chain.proceed(originalRequest);
}

View File

@ -6,7 +6,7 @@ public class SyncResponseModel {
private List<String> toBeUploaded;
private List<String> toBeDownloaded;
private List<String> toBeDeleted;
private List<SyncCreateResponse> createResonses;
private List<SyncCreateResponse> createResponses;
public List<String> getToBeUploaded() {
return toBeUploaded;
@ -32,11 +32,11 @@ public class SyncResponseModel {
this.toBeDeleted = toBeDeleted;
}
public List<SyncCreateResponse> getCreateResonses() {
return createResonses;
public List<SyncCreateResponse> getCreateResponses() {
return createResponses;
}
public void setCreateResonses(List<SyncCreateResponse> createResonses) {
this.createResonses = createResonses;
public void setCreateResponses(List<SyncCreateResponse> createResponses) {
this.createResponses = createResponses;
}
}