Skip to content

Commit f20e816

Browse files
authored
Fix authorisation for all backend routes (#994)
1 parent 4511587 commit f20e816

File tree

14 files changed

+199
-35
lines changed

14 files changed

+199
-35
lines changed

client/src/api/getAutoTimetable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const getAutoTimetable = async (data: any): Promise<[number[], boolean]> => {
1010
'Content-Type': 'application/json',
1111
},
1212
body: JSON.stringify(data),
13+
credentials: 'include',
1314
});
1415

1516
if (res.status !== 201) {

client/src/components/sidebar/groupsSidebar/AddOrEditGroupDialogContent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const AddOrEditGroupDialogContent: React.FC<AddGroupDialogContentProps> = ({
112112
groupAdminIDs: group.groupAdmins.map((groupAdmin) => groupAdmin.userID),
113113
imageURL: group.imageURL,
114114
}),
115+
credentials: 'include',
115116
});
116117
const groupCreationStatus = await res.json();
117118
console.log('group creation status', groupCreationStatus.data); // Can see the status of group creation here!
@@ -144,6 +145,7 @@ const AddOrEditGroupDialogContent: React.FC<AddGroupDialogContentProps> = ({
144145
groupAdminIDs: group.groupAdmins.map((groupAdmin) => groupAdmin.userID),
145146
imageURL: group.imageURL,
146147
}),
148+
credentials: 'include',
147149
});
148150
const groupCreationStatus = await res.json();
149151
console.log('group update status', groupCreationStatus.data); // Can see the status of group creation here!

client/src/components/sidebar/groupsSidebar/GroupCircle.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const AdminMenu: React.FC<{
6161
Accept: 'application/json',
6262
'Content-Type': 'application/json',
6363
},
64+
credentials: 'include',
6465
});
6566
const groupDeleteStatus = await res.json();
6667
console.log('group delete status', groupDeleteStatus);
@@ -114,6 +115,7 @@ const MemberMenu: React.FC<{ userID: string; group: Group; fetchUserInfo: (userI
114115
groupAdminIDs: group.groupAdmins.map((groupAdmins) => groupAdmins.userID),
115116
imageURL: group.imageURL,
116117
}),
118+
credentials: 'include',
117119
});
118120
const leaveGroupStatus = await res.json();
119121
console.log('leave group status', leaveGroupStatus.data);

client/src/components/sidebar/groupsSidebar/friends/AddAFriendTab.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const AddAFriendTab: React.FC<{ user: User; fetchUserInfo: (userID: string) => v
4040
Accept: 'application/json',
4141
'Content-Type': 'application/json',
4242
},
43+
credentials: 'include',
4344
});
4445
if (res.status !== 200) throw new NetworkError("Couldn't get response");
4546
const getUsersStatus = await res.json();
@@ -83,6 +84,7 @@ const AddAFriendTab: React.FC<{ user: User; fetchUserInfo: (userID: string) => v
8384
senderId: user.userID,
8485
sendeeId: otherUserID,
8586
}),
87+
credentials: 'include',
8688
});
8789
if (res.status !== 201) throw new NetworkError("Couldn't get response");
8890
const acceptRequestStatus = await res.json();
@@ -105,6 +107,7 @@ const AddAFriendTab: React.FC<{ user: User; fetchUserInfo: (userID: string) => v
105107
sendeeId: otherUserID,
106108
senderId: user.userID,
107109
}),
110+
credentials: 'include',
108111
});
109112
if (res.status !== 200) throw new NetworkError("Couldn't get response");
110113
const declineRequestStatus = await res.json();

client/src/components/sidebar/groupsSidebar/friends/RequestsTab.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const RequestsTab: React.FC<{ user: User; fetchUserInfo: (userID: string) => voi
3737
sendeeId: user.userID,
3838
senderId: incomingUserId,
3939
}),
40+
credentials: 'include',
4041
});
4142
if (res.status !== 200) throw new NetworkError("Couldn't get response");
4243
const declineRequestStatus = await res.json();
@@ -59,6 +60,7 @@ const RequestsTab: React.FC<{ user: User; fetchUserInfo: (userID: string) => voi
5960
senderId: user.userID,
6061
sendeeId: incomingUserId,
6162
}),
63+
credentials: 'include',
6264
});
6365
if (res.status !== 201) throw new NetworkError("Couldn't get response");
6466
const acceptRequestStatus = await res.json();

client/src/components/sidebar/groupsSidebar/friends/YourFriendsTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const YourFriendsTab: React.FC<{ user: User; fetchUserInfo: (userID: string) =>
3232
senderId: user.userID,
3333
sendeeId: friendID,
3434
}),
35+
credentials: 'include',
3536
});
3637
if (res.status !== 200) throw new NetworkError("Couldn't get response");
3738
const acceptRequestStatus = await res.json();

client/src/context/UserContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const UserContextProvider = ({ children }: UserContextProviderProps) => {
6666
Accept: 'application/json',
6767
'Content-Type': 'application/json',
6868
},
69+
credentials: 'include',
6970
});
7071
const res = await response.json();
7172
const timetables = await Promise.all(
@@ -115,6 +116,7 @@ const UserContextProvider = ({ children }: UserContextProviderProps) => {
115116
Accept: 'application/json',
116117
'Content-Type': 'application/json',
117118
},
119+
credentials: 'include',
118120
});
119121
if (res.status !== 200) throw new NetworkError("Couldn't get response");
120122
const jsonData = await res.json();

client/src/utils/syncTimetables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export const syncAddTimetable = async (userId: string, newTimetable: TimetableDa
176176
name,
177177
mapKey: term,
178178
}),
179+
credentials: 'include',
179180
});
180181

181182
const json = await res.json();
@@ -193,6 +194,7 @@ const syncDeleteTimetable = async (timetableId: string) => {
193194
Accept: 'application/json',
194195
'Content-Type': 'application/json',
195196
},
197+
credentials: 'include',
196198
});
197199
} catch (e) {
198200
console.log(e);
@@ -215,6 +217,7 @@ const syncEditTimetable = async (userId: string, editedTimetable: TimetableData)
215217
userId: userId,
216218
timetable: convertTimetableToDTO(editedTimetable),
217219
}),
220+
credentials: 'include',
218221
});
219222
} catch (e) {
220223
console.log(e);

server/src/app.module.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { AppService } from './app.service';
55
import { AuthModule } from './auth/auth.module';
66
import { AutoModule } from './auto/auto.module';
77
import config from './config';
8-
import { FriendModule } from './friend/friend.module';
9-
import { GroupModule } from './group/group.module';
8+
// import { FriendModule } from './friend/friend.module';
9+
// import { GroupModule } from './group/group.module';
1010
import { PrismaModule } from './prisma/prisma.module';
1111
import { UserModule } from './user/user.module';
1212
import { GraphqlService } from './graphql/graphql.service';
1313
import { GraphqlModule } from './graphql/graphql.module';
14+
15+
// TOOD: Re-enable FriendModule and GroupModule when ready
16+
// Need to be locked down better, and FE supported
1417
@Module({
1518
imports: [
1619
ConfigModule.forRoot({
@@ -21,10 +24,10 @@ import { GraphqlModule } from './graphql/graphql.module';
2124
AuthModule,
2225
AutoModule,
2326
UserModule,
24-
FriendModule,
27+
// FriendModule,
2528
PrismaModule,
2629
GraphqlModule,
27-
GroupModule,
30+
// GroupModule,
2831
],
2932
controllers: [AppController],
3033
providers: [AppService, GraphqlService],

server/src/auth/auth.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ export class AuthController {
8383

8484
@Get('/logout')
8585
async logout(@Request() req, @Res() res: Response) {
86-
this.authService.logout(req, res);
86+
await this.authService.logout(req, res);
8787
}
8888
}

0 commit comments

Comments
 (0)