feat: UTRP v2 migration (#292)

* feat: wip add course by url

* chore: update imports

* feat: add useCourseFromUrl hook

* chore: extract logic into async function

* feat: add checkLoginStatus.ts

* feat: add useCourseMigration hook

* feat: working course migration

* fix: active schedule bug

* feat: refactor logic and add to onUpdate

* feat: update ui style

* feat: add changelog functionality to settings

* chore: update packages

* feat: migration + sentry stuffs

* feat: improve migration flow

* docs: add sentry jsdocs

* chore: fix lint and format

* chore: cleanup + fix race condition

---------

Co-authored-by: Samuel Gunter <sgunter@utexas.edu>
Co-authored-by: Razboy20 <razboy20@gmail.com>
This commit is contained in:
doprz
2024-10-14 21:30:37 -05:00
committed by GitHub
parent e774f316e3
commit d22237d561
23 changed files with 1980 additions and 1865 deletions

View File

@@ -0,0 +1,27 @@
/**
* Checks the login status by making a request to the provided URL.
* If the response indicates that the user is not logged in (redirected to a login page or returns a 401/403 status),
* it opens a new tab with the login URL and returns `false`.
* If the user is logged in, it returns `true`.
*
* @param url - The URL to check the login status against.
* @returns A promise that resolves to `true` if the user is logged in, otherwise `false`.
*/
export async function validateLoginStatus(url: string) {
try {
const response = await fetch(url, { credentials: 'include' });
// Check if the response is redirecting to a login page or returning a 401/403
if (response.redirected || response.status === 401 || response.status === 403) {
// User is not logged in
chrome.tabs.create({ url });
return false;
}
// User is logged in
return true;
} catch (error) {
console.error('Error checking login status:', error);
return false;
}
}