diff --git a/src/auth/actions.js b/src/auth/actions.js index 44066c2..14aab4a 100644 --- a/src/auth/actions.js +++ b/src/auth/actions.js @@ -11,26 +11,22 @@ import { import { getDeviceUuid } from "./deviceUuid"; -// to support refresh auth in headless mode we'll use fetch instead of apollo/axios +// to support refresh auth in headless mode we'll use axios instead of apollo // read more https://github.com/transistorsoft/react-native-background-fetch/issues/562 export async function registerUser() { - const response = await fetch(env.GRAPHQL_URL, { - method: "POST", - headers: { - "Content-Type": "application/json", - // No Authorization header for this request - }, - body: JSON.stringify({ + const { data } = await network.axios.post( + env.GRAPHQL_URL, + { query: REGISTER_USER_MUTATION_STRING, - }), - }); - - if (!response.ok) { - throw new Error(`HTTP Error: ${response.status} ${response.statusText}`); - } - - const data = await response.json(); + }, + { + headers: { + // Skip adding Authorization header for this request + Authorization: undefined, + }, + }, + ); if (data.errors && data.errors.length > 0) { const message = data.errors.map((err) => err.message).join("; "); @@ -43,27 +39,23 @@ export async function registerUser() { export async function loginUserToken({ authToken }) { const deviceUuid = await getDeviceUuid(); - const response = await fetch(env.GRAPHQL_URL, { - method: "POST", - headers: { - "Content-Type": "application/json", - // No Authorization header for this request - }, - body: JSON.stringify({ + const { data } = await network.axios.post( + env.GRAPHQL_URL, + { query: LOGIN_USER_TOKEN_MUTATION_STRING, variables: { authTokenJwt: authToken, phoneModel: Device.modelName, deviceUuid, }, - }), - }); - - if (!response.ok) { - throw new Error(`HTTP Error: ${response.status} ${response.statusText}`); - } - - const data = await response.json(); + }, + { + headers: { + // Skip adding Authorization header for this request + Authorization: undefined, + }, + }, + ); if (data.errors && data.errors.length > 0) { const message = data.errors.map((err) => err.message).join("; ");