Merge pull request #274 from ets-cfuhrman-pfe/debug-oidc-1
Some checks failed
CI/CD Pipeline for Backend / build_and_push_backend (push) Failing after 17s
CI/CD Pipeline for Nginx Router / build_and_push_nginx (push) Failing after 17s
CI/CD Pipeline for Frontend / build_and_push_frontend (push) Failing after 17s
Tests / lint-and-tests (client) (push) Failing after 1m7s
Tests / lint-and-tests (server) (push) Failing after 1m0s

hard-code teacher role
This commit is contained in:
Christopher (Cris) Fuhrman 2025-03-04 15:43:09 -05:00 committed by GitHub
commit 8412218bb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,6 +73,8 @@ class ApiService {
return false; return false;
} }
console.log("ApiService: isLoggedIn: Token:", token);
// Update token expiry // Update token expiry
this.saveToken(token); this.saveToken(token);
@ -88,11 +90,19 @@ class ApiService {
} }
try { try {
console.log("ApiService: isLoggedInTeacher: Token:", token);
const decodedToken = jwtDecode(token) as { roles: string[] }; const decodedToken = jwtDecode(token) as { roles: string[] };
/////// REMOVE BELOW
// automatically add teacher role if not present
if (!decodedToken.roles.includes('teacher')) {
decodedToken.roles.push('teacher');
}
////// REMOVE ABOVE
const userRoles = decodedToken.roles; const userRoles = decodedToken.roles;
const requiredRole = 'teacher'; const requiredRole = 'teacher';
console.log("ApiService: isLoggedInTeacher: UserRoles:", userRoles);
if (!userRoles || !userRoles.includes(requiredRole)) { if (!userRoles || !userRoles.includes(requiredRole)) {
return false; return false;
} }
@ -968,4 +978,4 @@ public async login(email: string, password: string): Promise<any> {
} }
const apiService = new ApiService(); const apiService = new ApiService();
export default apiService; export default apiService;