Skip to content

Commit

Permalink
fix android
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsc committed Oct 18, 2023
1 parent 94346f2 commit 832f6d8
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/

import { Injectable } from '@angular/core'
import { APIRequest, FormDataContainer, Method, RefreshTokenRequest } from '../requests/requests'
import { APIRequest, ApiTokenResponse, FormDataContainer, Method, RefreshTokenRequest } from '../requests/requests'
import { StorageService } from './storage.service'
import { ApiNetwork } from '../models/StorageTypes'
import { isDevMode } from '@angular/core'
import { Mutex } from 'async-mutex'
import { findConfigForKey, MAP } from '../utils/NetworkData'
import { CapacitorHttp, HttpResponse } from '@capacitor/core'
import { Capacitor, CapacitorHttp, HttpResponse } from '@capacitor/core'
import { CacheModule } from '../utils/CacheModule'
import axios, { AxiosResponse } from 'axios'
import { HttpOptions } from '@capacitor/core'
Expand Down Expand Up @@ -154,9 +154,27 @@ export class ApiService extends CacheModule {

const now = Date.now()
const req = new RefreshTokenRequest(user.refreshToken)
const resp = await this.execute(req)
const response = req.parse(resp)
const result = response[0]

let result: ApiTokenResponse
let resp
if (Capacitor.isNativePlatform() && Capacitor.getPlatform() == 'android') {
const formBody = new FormData()
formBody.set('grant_type', 'refresh_token')
formBody.set('refresh_token', user.refreshToken)
const url = await this.getResourceUrl(req.resource, req.endPoint)

resp = await fetch(url, {
method: 'POST',
body: formBody,
headers: await this.getAuthHeader(true),
})
result = await resp.json()
} else {

resp = await this.execute(req)
const response = req.parse(resp)
result = response[0]
}

console.log('Refresh token', result, resp)
if (!result || !result.access_token) {
Expand Down

0 comments on commit 832f6d8

Please sign in to comment.