Skip to content

Commit 3c9764b

Browse files
committed
TTA-180: fixing endpoints to send credentials
1 parent 2a85d69 commit 3c9764b

File tree

12 files changed

+65
-40
lines changed

12 files changed

+65
-40
lines changed

proxy.conf.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const PROXY_CONFIG = [
2+
{
3+
context: [
4+
'/api',
5+
],
6+
target: 'http://127.0.0.1:7071',
7+
changeOrigin: true,
8+
withCredentials: true,
9+
secure: false,
10+
headers: {
11+
'Connection': 'keep-alive'
12+
}
13+
}
14+
]
15+
16+
module.exports = PROXY_CONFIG;

src/app/modules/activities-management/services/activity.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ActivityService {
1414
constructor(private http: HttpClient) {}
1515

1616
getActivities(): Observable<Activity[]> {
17-
return this.http.get<Activity[]>(this.baseUrl);
17+
return this.http.get<Activity[]>(this.baseUrl, { withCredentials: true });
1818
}
1919

2020
createActivity(activityData): Observable<any> {
@@ -23,12 +23,12 @@ export class ActivityService {
2323
tenant_id: '4225ab1e-1033-4a5f-8650-0dd4950f38c8',
2424
};
2525

26-
return this.http.post(this.baseUrl, body);
26+
return this.http.post(this.baseUrl, body, { withCredentials: true });
2727
}
2828

2929
deleteActivity(acitivityId: string): Observable<any> {
3030
const url = `${this.baseUrl}/${acitivityId}`;
31-
return this.http.delete(url);
31+
return this.http.delete(url, { withCredentials: true });
3232
}
3333

3434
updateActivity(activityData): Observable<any> {
@@ -38,6 +38,6 @@ export class ActivityService {
3838
...activityData,
3939
};
4040

41-
return this.http.put(url, body);
41+
return this.http.put(url, body, { withCredentials: true });
4242
}
4343
}

src/app/modules/customer-management/components/projects-type/services/project-type.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ export class ProjectTypeService {
1515

1616
getProjectTypes(customerId: any): Observable<ProjectType[]> {
1717
const params = new HttpParams().set('customer_id', customerId.customerId);
18-
return this.http.get<ProjectType[]>(this.baseUrl, { params });
18+
return this.http.get<ProjectType[]>(this.baseUrl, { params, withCredentials: true });
1919
}
2020

2121
createProjectType(projectTypeData): Observable<any> {
22-
return this.http.post(this.baseUrl, projectTypeData);
22+
return this.http.post(this.baseUrl, projectTypeData, { withCredentials: true });
2323
}
2424

2525
deleteProjectType(projectTypeId: string): Observable<any> {
2626
const url = `${this.baseUrl}/${projectTypeId}`;
27-
return this.http.delete(url);
27+
return this.http.delete(url, { withCredentials: true });
2828
}
2929

3030
updateProjectType(projectTypeData): Observable<any> {
3131
const url = `${this.baseUrl}/${projectTypeData.id}`;
32-
return this.http.put(url, projectTypeData);
32+
return this.http.put(url, projectTypeData, { withCredentials: true });
3333
}
3434
}

src/app/modules/customer-management/components/projects/components/services/project.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ export class ProjectService {
1717

1818
getProjects(customerId: any): Observable<Project[]> {
1919
const params = new HttpParams().set('customer_id', customerId.customerId);
20-
return this.http.get<Project[]>(this.url, { params });
20+
return this.http.get<Project[]>(this.url, { params, withCredentials: true });
2121
}
2222

2323
getAllProjects(): Observable<Project[]> {
24-
return this.http.get<Project[]>(this.url);
24+
return this.http.get<Project[]>(this.url, { withCredentials: true });
2525
}
2626

2727
getRecentProjects(): Observable<Project[]> {
28-
return this.http.get<Project[]>(`${this.url}/recent`);
28+
return this.http.get<Project[]>(`${this.url}/recent`, { withCredentials: true });
2929
}
3030

3131
createProject(projectData): Observable<any> {
32-
return this.http.post<Project[]>(this.url, projectData);
32+
return this.http.post<Project[]>(this.url, projectData, { withCredentials: true });
3333
}
3434

3535
updateProject(projectData): Observable<any> {
@@ -39,12 +39,12 @@ export class ProjectService {
3939
projectData.status = 1;
4040
}
4141
}
42-
return this.http.put(`${this.url}/${id}`, projectData);
42+
return this.http.put(`${this.url}/${id}`, projectData, { withCredentials: true });
4343
}
4444

4545
deleteProject(projectId: string): Observable<any> {
4646
return this.isDevelopmentOrProd
4747
? this.http.put(`${this.url}/${projectId}`, { status: 0 })
48-
: this.http.delete(`${this.url}/${projectId}`);
48+
: this.http.delete(`${this.url}/${projectId}`, { withCredentials: true });
4949
}
5050
}

src/app/modules/customer-management/services/customer.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ export class CustomerService {
1313
constructor(private http: HttpClient) {}
1414

1515
createCustomer(customerData): Observable<any> {
16-
return this.http.post(this.baseUrl, customerData);
16+
return this.http.post(this.baseUrl, customerData, { withCredentials: true });
1717
}
1818

1919
getCustomers(): Observable<any> {
20-
return this.http.get(this.baseUrl);
20+
return this.http.get(this.baseUrl, { withCredentials: true });
2121
}
2222

2323
deleteCustomer(customerId: string): Observable<any> {
2424
const url = `${this.baseUrl}/${customerId}`;
25-
return this.http.delete(url);
25+
return this.http.delete(url, { withCredentials: true });
2626
}
2727

2828
updateCustomer(customerData): Observable<any> {
2929
const url = `${this.baseUrl}/${customerData.id}`;
30-
return this.http.put(url, customerData);
30+
return this.http.put(url, customerData, { withCredentials: true });
3131
}
3232
}

src/app/modules/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ <h3>Please log in</h3>
1111
<button (click)="login() " class="btn btn-primary">login</button>
1212
</div>
1313
<div *ngIf="!isProduction">
14-
<a ng-href="{cliendId}}">Login</a>
14+
<a href="https://uat-backend.auth.ioet.com/authn/login/timeTracker">Login</a>
1515
</div>
1616
</div>

src/app/modules/login/login.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export class LoginComponent implements OnInit {
8585
this.ngZone.run(() => this.router.navigate(['']));
8686
});
8787
};
88+
this.loginService.getUser('test').subscribe((resp) => {
89+
this.loginService.setCookies();
90+
const tokenObject = JSON.stringify(resp);
91+
console.log(tokenObject)
92+
const tokenJson = JSON.parse(tokenObject);
93+
this.loginService.setLocalStorage('user', tokenJson.token);
94+
this.ngZone.run(() => this.router.navigate(['']));
95+
});
8896
}
8997

9098
login(): void {
@@ -107,7 +115,7 @@ export class LoginComponent implements OnInit {
107115
}
108116

109117
loginAuth(): void {
110-
118+
111119
}
112120

113121
}

src/app/modules/login/services/login.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpClient } from '@angular/common/http';
1+
import { HttpClient, HttpHeaders } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { CookieService } from 'ngx-cookie-service';
44
import { EnvironmentType, UserEnum } from 'src/environments/enum';
@@ -92,7 +92,7 @@ export class LoginService {
9292
token: tokenString,
9393
};
9494

95-
return this.http.post(`${this.baseUrl}/login`, body);
95+
return this.http.post(`${this.baseUrl}/login`, body, { withCredentials: true });
9696
}
9797

9898
setCookies() {
@@ -109,7 +109,7 @@ export class LoginService {
109109

110110
isValidToken(token: string) {
111111
const body = { token };
112-
return this.http.post(`${this.baseUrl}/validate-token`, body).pipe(
112+
return this.http.post(`${this.baseUrl}/validate-token`, body, { withCredentials: true }).pipe(
113113
map((response) => {
114114
const responseString = JSON.stringify(response);
115115
const responseJson = JSON.parse(responseString);

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,49 @@ export class EntryService {
2323
urlInProductionLegacy = environment.production === EnvironmentType.TT_PROD_LEGACY;
2424

2525
loadActiveEntry(): Observable<any> {
26-
return this.http.get(`${this.baseUrl}/running`);
26+
return this.http.get(`${this.baseUrl}/running`, { withCredentials: true });
2727
}
2828

2929
loadEntries(date): Observable<any> {
3030
const timezoneOffset = new Date().getTimezoneOffset();
31-
return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`);
31+
return this.http.get(`${this.baseUrl}?month=${date.month}&year=${date.year}&timezone_offset=${timezoneOffset}`, { withCredentials: true });
3232
}
3333

3434
createEntry(entryData): Observable<any> {
35-
return this.http.post(this.baseUrl, entryData);
35+
return this.http.post(this.baseUrl, entryData, { withCredentials: true });
3636
}
3737

3838
updateEntry(entryData): Observable<any> {
3939
const {id} = entryData;
40-
return this.http.put(`${this.baseUrl}/${id}`, entryData);
40+
return this.http.put(`${this.baseUrl}/${id}`, entryData, { withCredentials: true });
4141
}
4242

4343
deleteEntry(entryId: string): Observable<any> {
4444
const url = `${this.baseUrl}/${entryId}`;
45-
return this.http.delete(url);
45+
return this.http.delete(url, { withCredentials: true });
4646
}
4747

4848
stopEntryRunning(idEntry: string): Observable<any> {
4949
return (this.urlInProductionLegacy ?
50-
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) );
50+
this.http.post(`${this.baseUrl}/${idEntry}/stop`, null, { withCredentials: true }) : this.http.put(`${this.baseUrl}/stop`, null, { withCredentials: true }) );
5151
}
5252

5353
restartEntry(idEntry: string): Observable<Entry> {
5454
const url = `${this.baseUrl}/${idEntry}/restart`;
55-
return this.http.post<Entry>(url, null);
55+
return this.http.post<Entry>(url, null, { withCredentials: true });
5656
}
5757

5858
summary(): Observable<TimeEntriesSummary> {
5959
const timeOffset = new Date().getTimezoneOffset();
6060
const summaryUrl = `${this.baseUrl}/summary?time_offset=${timeOffset}`;
61-
return this.http.get<TimeEntriesSummary>(summaryUrl);
61+
return this.http.get<TimeEntriesSummary>(summaryUrl, { withCredentials: true });
6262
}
6363

6464
findEntriesByProjectId(projectId: string): Observable<Entry[]> {
6565
const startDate = this.getDateLastMonth();
6666
const endDate = this.getCurrentDate();
6767
const findEntriesByProjectURL = `${this.baseUrl}?limit=2&project_id=${projectId}&start_date=${startDate}&end_date=${endDate}`;
68-
return this.http.get<Entry[]>(findEntriesByProjectURL);
68+
return this.http.get<Entry[]>(findEntriesByProjectURL, { withCredentials: true });
6969
}
7070

7171
loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string): Observable<any> {
@@ -79,7 +79,8 @@ export class EntryService {
7979
user_id: userId,
8080
limit: `${MAX_NUMBER_OF_ENTRIES_FOR_REPORTS}`,
8181
timezone_offset : new Date().getTimezoneOffset().toString(),
82-
}
82+
},
83+
withCredentials: true
8384
}
8485
);
8586
}

src/app/modules/user/services/user.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export class UserService {
1616

1717
loadUser(userId: any): Observable<User> {
1818
const url = `${this.baseUrl}/${userId}`;
19-
return this.http.get<User>(url);
19+
return this.http.get<User>(url, { withCredentials: true });
2020
}
2121
}

0 commit comments

Comments
 (0)