Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api-client
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
frontend
libraries
api-client
Commits
b342e42b
Commit
b342e42b
authored
3 years ago
by
Benedikt Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
Update: Handle LocalStorage Coscine Values (coscine/issues#1833)
parent
944a5b96
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!15
Update: Handle LocalStorage Coscine Values (coscine/issues#1833)
Changes
4
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/apis.ts
+6
-1
6 additions, 1 deletion
src/apis.ts
src/axios-basic.ts
+32
-8
32 additions, 8 deletions
src/axios-basic.ts
src/index.ts
+2
-0
2 additions, 0 deletions
src/index.ts
yarn.lock-workspace
+1279
-1163
1279 additions, 1163 deletions
yarn.lock-workspace
with
1319 additions
and
1172 deletions
src/apis.ts
+
6
−
1
View file @
b342e42b
...
@@ -29,7 +29,12 @@ import { UserApiFactory } from './Coscine.Api.User/api';
...
@@ -29,7 +29,12 @@ import { UserApiFactory } from './Coscine.Api.User/api';
let
accessToken
=
''
;
let
accessToken
=
''
;
if
(
typeof
coscine
!==
'
undefined
'
&&
typeof
coscine
.
authorization
!==
'
undefined
'
)
{
if
(
typeof
coscine
!==
'
undefined
'
&&
typeof
coscine
.
authorization
!==
'
undefined
'
)
{
accessToken
=
coscine
.
authorization
.
bearer
;
accessToken
=
'
Bearer
'
+
coscine
.
authorization
.
bearer
;
}
// LocalStorage > Global Variables
const
localStorageToken
=
localStorage
.
getItem
(
'
coscine.authorization.bearer
'
);
if
(
localStorageToken
)
{
accessToken
=
'
Bearer
'
+
localStorageToken
;
}
}
const
getHostName
=
()
=>
{
const
getHostName
=
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/axios-basic.ts
+
32
−
8
View file @
b342e42b
...
@@ -15,27 +15,51 @@ function setHeader(request: AxiosRequestConfig) {
...
@@ -15,27 +15,51 @@ function setHeader(request: AxiosRequestConfig) {
request
.
headers
.
common
[
clientCorrolationIdKey
]
=
coscine
.
clientcorrolation
.
id
;
request
.
headers
.
common
[
clientCorrolationIdKey
]
=
coscine
.
clientcorrolation
.
id
;
}
}
}
}
// LocalStorage > Global Variables
const
localStorageToken
=
localStorage
.
getItem
(
"
coscine.authorization.bearer
"
);
if
(
localStorageToken
)
{
request
.
headers
.
common
[
authHeaderKey
]
=
'
Bearer
'
+
localStorageToken
;
}
const
localStorageClientCorrelation
=
localStorage
.
getItem
(
"
coscine.clientcorrolation.id
"
);
if
(
localStorageClientCorrelation
)
{
request
.
headers
.
common
[
clientCorrolationIdKey
]
=
localStorageClientCorrelation
;
}
};
};
instance
.
interceptors
.
request
.
use
((
request
:
AxiosRequestConfig
)
=>
{
function
increaseLoading
()
{
setHeader
(
request
);
if
((
typeof
coscine
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
.
counter
!==
"
undefined
"
))
{
if
((
typeof
coscine
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
.
counter
!==
"
undefined
"
))
{
coscine
.
loading
.
counter
++
;
coscine
.
loading
.
counter
++
;
}
}
const
localStorageLoading
=
localStorage
.
getItem
(
"
coscine.loading.counter
"
);
if
(
localStorageLoading
)
{
localStorage
.
setItem
(
"
coscine.loading.counter
"
,
String
(
Number
(
localStorageLoading
)
+
1
));
}
}
function
decreaseLoading
()
{
if
((
typeof
coscine
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
.
counter
!==
"
undefined
"
))
{
coscine
.
loading
.
counter
--
;
}
const
localStorageLoading
=
localStorage
.
getItem
(
"
coscine.loading.counter
"
);
if
(
localStorageLoading
)
{
localStorage
.
setItem
(
"
coscine.loading.counter
"
,
String
(
Number
(
localStorageLoading
)
-
1
));
}
}
instance
.
interceptors
.
request
.
use
((
request
:
AxiosRequestConfig
)
=>
{
setHeader
(
request
);
increaseLoading
();
return
request
;
return
request
;
},
(
error
:
unknown
)
=>
{
},
(
error
:
unknown
)
=>
{
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
});
});
instance
.
interceptors
.
response
.
use
((
response
:
AxiosRequestConfig
)
=>
{
instance
.
interceptors
.
response
.
use
((
response
:
AxiosRequestConfig
)
=>
{
if
((
typeof
coscine
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
.
counter
!==
"
undefined
"
))
{
decreaseLoading
();
coscine
.
loading
.
counter
--
;
}
return
response
;
return
response
;
},
(
error
:
unknown
)
=>
{
},
(
error
:
unknown
)
=>
{
if
((
typeof
coscine
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
!==
"
undefined
"
)
&&
(
typeof
coscine
.
loading
.
counter
!==
"
undefined
"
))
{
decreaseLoading
();
coscine
.
loading
.
counter
--
;
}
return
Promise
.
reject
(
error
);
return
Promise
.
reject
(
error
);
});
});
...
...
This diff is collapsed.
Click to expand it.
src/index.ts
+
2
−
0
View file @
b342e42b
import
implementations
from
'
./apis
'
;
import
implementations
from
'
./apis
'
;
import
instance
from
'
./axios-basic
'
;
import
instance
from
'
./axios-basic
'
;
export
{
implementations
as
apiImplementations
,
instance
as
axiosInstance
};
const
apis
=
implementations
(
instance
);
const
apis
=
implementations
(
instance
);
export
const
ActivatedFeaturesApi
=
apis
.
ActivatedFeaturesApi
;
export
const
ActivatedFeaturesApi
=
apis
.
ActivatedFeaturesApi
;
...
...
This diff is collapsed.
Click to expand it.
yarn.lock-workspace
+
1279
−
1163
View file @
b342e42b
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