Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PortalMEC-React
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PortalMEC
PortalMEC-React
Commits
087f7110
Commit
087f7110
authored
4 years ago
by
lfr20
Browse files
Options
Downloads
Patches
Plain Diff
Copy and paste from 'develop'
parent
1a56b6fa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!57
Merge of develop into master
,
!56
Fixed buttons reportar, seguir, compartilhar, guardar and entrar (in comments...
,
!39
Update admin system
,
!36
Fix perfil into develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Components/HelperFunctions/getAxiosConfig.js
+90
-49
90 additions, 49 deletions
src/Components/HelperFunctions/getAxiosConfig.js
with
90 additions
and
49 deletions
src/Components/HelperFunctions/getAxiosConfig.js
+
90
−
49
View file @
087f7110
import
{
apiUrl
}
from
'
../../env.js
'
import
axios
from
'
axios
'
export
function
getAxiosConfigFromJSON
()
{
let
config
=
{
...
...
@@ -79,25 +78,39 @@ function updateAccessToken (newAccessToken) {
}
}
export
const
getRequest
=
(
url
,
onSuccess
,
onError
)
=>
{
fetch
((
`
${
apiUrl
}${
url
}
`
),
{
export
async
function
getRequest
(
url
,
onSuccess
,
onError
)
{
let
response
=
await
fetch
((
`
${
apiUrl
}${
url
}
`
),
{
headers
:
fetchHeaders
()
})
.
then
(
response
=>
{
if
(
response
.
headers
.
has
(
'
access-token
'
))
{
updateAccessToken
(
response
.
headers
.
get
(
'
access-token
'
))
}
return
response
.
json
().
catch
(
err
=>
{
return
{};
})
})
.
then
(
data
=>
{
console
.
log
(
data
)
onSuccess
(
data
)
})
.
catch
(
error
=>
{
onError
(
error
)
})
if
(
response
.
ok
)
{
if
(
response
.
headers
.
has
(
'
access-token
'
))
{
updateAccessToken
(
response
.
headers
.
get
(
'
access-token
'
))
}
let
json
=
await
response
.
json
()
onSuccess
(
json
,
response
.
headers
)
}
else
{
onError
(
response
.
error
)
}
// .then(response => {
// if (response.headers.has('access-token')) {
// updateAccessToken(response.headers.get('access-token'))
// }
// let json = await response.json()
//
// onSuccess(json)
//
// return response.json().catch(err => {
// return {};
// })
// })
// .then(data => {
// onSuccess(data)
// })
// .catch(error => {
// onError(error)
// })
}
export
const
deleteRequest
=
(
url
,
onSuccess
,
onError
)
=>
{
...
...
@@ -114,7 +127,6 @@ export const deleteRequest = (url, onSuccess, onError) => {
})
})
.
then
(
data
=>
{
console
.
log
(
data
)
onSuccess
(
data
)
})
.
catch
(
error
=>
{
...
...
@@ -124,10 +136,7 @@ export const deleteRequest = (url, onSuccess, onError) => {
export
const
putRequest
=
(
url
,
payload
,
onSuccess
,
onError
)
=>
{
let
newHeaders
=
fetchHeaders
()
if
(
payload
instanceof
FormData
)
{
newHeaders
.
append
(
'
Content-Type
'
,
'
multipart/form-data
'
)
}
else
{
if
(
!
(
payload
instanceof
FormData
))
{
newHeaders
.
append
(
'
Content-Type
'
,
'
application/json
'
)
}
...
...
@@ -145,7 +154,6 @@ export const putRequest = (url, payload, onSuccess, onError) => {
})
})
.
then
(
data
=>
{
console
.
log
(
data
)
onSuccess
(
data
)
})
.
catch
(
error
=>
{
...
...
@@ -176,7 +184,6 @@ export const postRequest = (url, payload, onSuccess, onError) => {
})
})
.
then
(
data
=>
{
console
.
log
(
data
)
onSuccess
(
data
)
})
.
catch
(
error
=>
{
...
...
@@ -189,9 +196,7 @@ export const fetchAllRequest = (urls, onSuccess, onError) => {
headers
:
fetchHeaders
()
}))).
then
(
(
responses
)
=>
{
for
(
let
res
of
responses
)
{
console
.
log
(
res
)
if
(
res
.
headers
.
has
(
'
access-token
'
)
&&
res
.
status
!==
304
)
{
console
.
log
(
res
)
updateAccessToken
(
res
.
headers
.
get
(
'
access-token
'
))
}
}
...
...
@@ -205,31 +210,13 @@ export const fetchAllRequest = (urls, onSuccess, onError) => {
})
}
export
const
validateGoogleLoginToken
=
(
config
,
onSuccess
,
onError
)
=>
{
axios
.
get
(
(
`
${
apiUrl
}
/auth/validate_token/`
),
config
).
then
(
(
response
)
=>
{
export
const
validateGoogleLoginToken
=
(
url
,
config
,
onSuccess
,
onError
)
=>
{
const
newHeaders
=
new
Headers
(
config
.
headers
)
if
(
response
.
headers
[
'
access-token
'
]
)
{
updateHeaders
(
response
.
headers
)
}
onSuccess
(
response
.
data
)
},
(
error
)
=>
{
onError
(
error
)
}
)
}
export
const
authentication
=
(
url
,
payload
,
onSuccess
,
onError
)
=>
{
let
formData
=
new
FormData
()
for
(
const
[
key
,
value
]
of
Object
.
entries
(
payload
))
{
formData
.
append
(
`
${
key
}
`
,
value
);
}
fetch
((
`
${
apiUrl
}${
url
}
`
),
{
method
:
'
POS
T
'
,
body
:
formData
method
:
'
GE
T
'
,
headers
:
newHeaders
})
.
then
(
response
=>
{
const
auth_headers
=
{
...
...
@@ -253,5 +240,59 @@ export const authentication = (url, payload, onSuccess, onError) => {
.
catch
(
error
=>
{
onError
(
error
)
})
}
export
async
function
authentication
(
url
,
payload
,
onSuccess
,
onError
)
{
let
formData
=
new
FormData
()
for
(
const
[
key
,
value
]
of
Object
.
entries
(
payload
))
{
formData
.
append
(
`
${
key
}
`
,
value
);
}
let
response
=
await
fetch
((
`
${
apiUrl
}${
url
}
`
),
{
method
:
'
POST
'
,
body
:
formData
})
if
(
response
.
ok
)
{
const
auth_headers
=
{
client
:
response
.
headers
.
get
(
'
client
'
),
"
access-token
"
:
response
.
headers
.
get
(
'
access-token
'
),
uid
:
response
.
headers
.
get
(
'
uid
'
),
expiry
:
response
.
headers
.
get
(
'
expiry
'
),
"
token-type
"
:
"
Bearer
"
}
sessionStorage
.
setItem
(
'
@portalmec/auth_headers
'
,
JSON
.
stringify
(
auth_headers
))
let
json
=
await
response
.
json
().
catch
(
err
=>
{
return
{};
})
onSuccess
(
json
)
}
else
{
onError
(
response
.
error
)
}
// .then(response => {
// const auth_headers = {
// client: response.headers.get('client'),
// "access-token": response.headers.get('access-token'),
// uid: response.headers.get('uid'),
// expiry: response.headers.get('expiry'),
// "token-type": "Bearer"
// }
//
// sessionStorage.setItem('@portalmec/auth_headers', JSON.stringify(auth_headers))
//
// return response.json().catch(err => {
// return {};
// })
// })
// .then(data => {
// console.log(data)
// onSuccess(data)
// })
// .catch(error => {
// onError(error)
// })
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment