frontend: reorder guards in base routes to fix bug when redirecting to error page
This commit is contained in:
parent
29019f82ff
commit
5f71b0c28a
@ -3,6 +3,41 @@ import { ActivatedRouteSnapshot, CanActivateFn, RouterStateSnapshot } from '@ang
|
|||||||
import { ErrorReason } from '@lib/models';
|
import { ErrorReason } from '@lib/models';
|
||||||
import { NavigationService, ParticipantService, RecordingService, RoomService } from '@lib/services';
|
import { NavigationService, ParticipantService, RecordingService, RoomService } from '@lib/services';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Guard to validate access to a room by generating a participant token.
|
||||||
|
*/
|
||||||
|
export const validateRoomAccessGuard: CanActivateFn = async (
|
||||||
|
_route: ActivatedRouteSnapshot,
|
||||||
|
_state: RouterStateSnapshot
|
||||||
|
) => {
|
||||||
|
const roomService = inject(RoomService);
|
||||||
|
const participantTokenService = inject(ParticipantService);
|
||||||
|
const navigationService = inject(NavigationService);
|
||||||
|
|
||||||
|
const roomId = roomService.getRoomId();
|
||||||
|
const secret = roomService.getRoomSecret();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await participantTokenService.generateToken({
|
||||||
|
roomId,
|
||||||
|
secret
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('Error generating participant token:', error);
|
||||||
|
switch (error.status) {
|
||||||
|
case 400:
|
||||||
|
// Invalid secret
|
||||||
|
return navigationService.redirectToErrorPage(ErrorReason.INVALID_ROOM_SECRET);
|
||||||
|
case 404:
|
||||||
|
// Room not found
|
||||||
|
return navigationService.redirectToErrorPage(ErrorReason.INVALID_ROOM);
|
||||||
|
default:
|
||||||
|
return navigationService.redirectToErrorPage(ErrorReason.INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guard to validate the access to recordings of a room by generating a recording token.
|
* Guard to validate the access to recordings of a room by generating a recording token.
|
||||||
*/
|
*/
|
||||||
@ -44,38 +79,3 @@ export const validateRecordingAccessGuard: CanActivateFn = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Guard to validate access to a room by generating a participant token.
|
|
||||||
*/
|
|
||||||
export const validateRoomAccessGuard: CanActivateFn = async (
|
|
||||||
_route: ActivatedRouteSnapshot,
|
|
||||||
_state: RouterStateSnapshot
|
|
||||||
) => {
|
|
||||||
const roomService = inject(RoomService);
|
|
||||||
const participantTokenService = inject(ParticipantService);
|
|
||||||
const navigationService = inject(NavigationService);
|
|
||||||
|
|
||||||
const roomId = roomService.getRoomId();
|
|
||||||
const secret = roomService.getRoomSecret();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await participantTokenService.generateToken({
|
|
||||||
roomId,
|
|
||||||
secret
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error generating participant token:', error);
|
|
||||||
switch (error.status) {
|
|
||||||
case 400:
|
|
||||||
// Invalid secret
|
|
||||||
return navigationService.redirectToErrorPage(ErrorReason.INVALID_ROOM_SECRET);
|
|
||||||
case 404:
|
|
||||||
// Room not found
|
|
||||||
return navigationService.redirectToErrorPage(ErrorReason.INVALID_ROOM);
|
|
||||||
default:
|
|
||||||
return navigationService.redirectToErrorPage(ErrorReason.INTERNAL_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@ -39,9 +39,9 @@ export const baseRoutes: Routes = [
|
|||||||
canActivate: [
|
canActivate: [
|
||||||
runGuardsSerially(
|
runGuardsSerially(
|
||||||
extractRoomQueryParamsGuard,
|
extractRoomQueryParamsGuard,
|
||||||
removeRoomSecretGuard,
|
|
||||||
checkParticipantRoleAndAuthGuard,
|
checkParticipantRoleAndAuthGuard,
|
||||||
validateRoomAccessGuard
|
validateRoomAccessGuard,
|
||||||
|
removeRoomSecretGuard
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -51,9 +51,9 @@ export const baseRoutes: Routes = [
|
|||||||
canActivate: [
|
canActivate: [
|
||||||
runGuardsSerially(
|
runGuardsSerially(
|
||||||
extractRecordingQueryParamsGuard,
|
extractRecordingQueryParamsGuard,
|
||||||
removeRoomSecretGuard,
|
|
||||||
checkParticipantRoleAndAuthGuard,
|
checkParticipantRoleAndAuthGuard,
|
||||||
validateRecordingAccessGuard
|
validateRecordingAccessGuard,
|
||||||
|
removeRoomSecretGuard
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user