Skip to content

Commit

Permalink
fix: handle nativeAuth's defaults in function body
Browse files Browse the repository at this point in the history
  • Loading branch information
Kipras Melnikovas authored and kiprasmel committed Sep 30, 2020
1 parent c4b6fb6 commit 85078b3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/gitbeaker-requester-utils/src/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ export class BaseService {
token,
jobToken,
oauthToken,
nativeAuth = {
gitlabSessionCookieKey: '_gitlab_session',
gitlabSessionCookieValue: '',
gitlabCSRFTokenKey: 'authenticity_token',
gitlabCSRFTokenValue: '',
},
nativeAuth,
sudo,
profileToken,
requester,
Expand Down Expand Up @@ -77,21 +72,26 @@ export class BaseService {
else if (jobToken) this.headers['job-token'] = jobToken;
else if (token) this.headers['private-token'] = token;

else if (nativeAuth.gitlabSessionCookieValue && nativeAuth.gitlabCSRFTokenValue) {
else if (nativeAuth?.gitlabSessionCookieValue && nativeAuth?.gitlabCSRFTokenValue) {
/**
* handle the defaults here, since if the `nativeAuth` is an object,
* and if these fields aren't provided but others are -
* the defaults @ param initialization would get overridden.
*/
const {
gitlabSessionCookieKey,
gitlabSessionCookieKey = '_gitlab_session',
gitlabSessionCookieValue,
gitlabCSRFTokenKey,
gitlabCSRFTokenKey = 'authenticity_token',
gitlabCSRFTokenValue,
} = nativeAuth;

this.additionalBody = { ...this.additionalBody, [gitlabCSRFTokenKey]: gitlabCSRFTokenValue };

if (!this.headers.cookie) {
this.headers.cookie = 'cookie: ';
}

this.headers.cookie += `${gitlabSessionCookieKey}=${gitlabSessionCookieValue}; `;

this.additionalBody = {...this.additionalBody, [gitlabCSRFTokenKey]: gitlabCSRFTokenValue}
}

// Profiling
Expand Down

0 comments on commit 85078b3

Please sign in to comment.