🛂 Add key-based permission system
This commit is contained in:
37
src/store.js
37
src/store.js
@ -72,6 +72,7 @@ export const timetable = computed(() => {
|
||||
localTimetable || remoteTimetable || { trusted: true, source: "", data: [] }
|
||||
);
|
||||
});
|
||||
export const sessionInfo = ref({});
|
||||
export const timetables = ref([]);
|
||||
export const times = ref([]);
|
||||
export const substitutions = ref({});
|
||||
@ -81,7 +82,7 @@ export const classList = ref([]);
|
||||
/* API functions */
|
||||
// Set the `VITE_API_ENDPOINT` env variable when
|
||||
// building the frontend to use an external api server
|
||||
const baseUrl = import.meta.env.VITE_API_ENDPOINT || "/api";
|
||||
export const baseUrl = import.meta.env.VITE_API_ENDPOINT || "/api";
|
||||
|
||||
export async function fetchData(days, partial) {
|
||||
if (!timetable.value.data || Object.keys(classList.value).length == 0) {
|
||||
@ -96,23 +97,12 @@ export async function fetchData(days, partial) {
|
||||
|
||||
// Check if the API server is reachable
|
||||
// and the user is authenticated
|
||||
try {
|
||||
const checkResponse = await fetch(`${baseUrl}/check`);
|
||||
if (checkResponse.status == 401) {
|
||||
shouldLogin.value = true;
|
||||
return;
|
||||
} else if (checkResponse.status != 200) {
|
||||
loadingFailed.value = true;
|
||||
loadingProgress.value = 1;
|
||||
console.log("Other error while fetching data: " + checkResponse.status);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
if (!(await fetchSessionInfo())) {
|
||||
loadingFailed.value = true;
|
||||
loadingProgress.value = 1;
|
||||
console.log("Error while fetching data: No internet connection!");
|
||||
return;
|
||||
}
|
||||
|
||||
loadingProgress.value = step++ / steps;
|
||||
|
||||
if (!partial) {
|
||||
@ -137,6 +127,25 @@ watch(selectedDate, () =>
|
||||
fetchData(getNextAndPrevDay(selectedDate.value), true)
|
||||
);
|
||||
|
||||
export async function fetchSessionInfo() {
|
||||
try {
|
||||
const checkResponse = await fetch(`${baseUrl}/info`);
|
||||
if (checkResponse.status == 401) {
|
||||
shouldLogin.value = true;
|
||||
return false;
|
||||
} else if (checkResponse.status != 200) {
|
||||
console.log("Other error while fetching data: " + checkResponse.status);
|
||||
return false;
|
||||
} else {
|
||||
sessionInfo.value = await checkResponse.json();
|
||||
}
|
||||
} catch {
|
||||
console.log("Error while fetching data: No internet connection!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function fetchClassList() {
|
||||
const classListResponse = await fetch(`${baseUrl}/classes`);
|
||||
const classListData = await classListResponse.json();
|
||||
|
||||
Reference in New Issue
Block a user