fix auth handling

This commit is contained in:
chark1es 2025-02-02 04:24:06 -08:00
parent f9274a319a
commit 4ea541fc64

View file

@ -142,8 +142,9 @@ export class StoreAuth {
// Public method to update profile settings // Public method to update profile settings
public async updateProfileSettings(data: { public async updateProfileSettings(data: {
major?: string; major?: string | null;
graduation_year?: string | number; graduation_year?: number | null;
member_id?: string | null;
}) { }) {
const user = this.pb.authStore.model; const user = this.pb.authStore.model;
if (!user?.id) { if (!user?.id) {
@ -153,6 +154,37 @@ export class StoreAuth {
return await this.pb.collection("users").update(user.id, data); return await this.pb.collection("users").update(user.id, data);
} }
/**
* Handles uploading a resume file for the current user
* @param file The resume file to upload
* @returns Promise that resolves when the resume is uploaded
*/
public async handleResumeUpload(file: File) {
const user = this.pb.authStore.model;
if (!user?.id) {
throw new Error("User ID not found");
}
// Validate file type
const allowedTypes = ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
if (!allowedTypes.includes(file.type)) {
throw new Error("Invalid file type. Please upload a PDF or Word document.");
}
// Validate file size (5MB max)
const maxSize = 5 * 1024 * 1024; // 5MB in bytes
if (file.size > maxSize) {
throw new Error("File size too large. Maximum size is 5MB.");
}
// Create form data with the file
const formData = new FormData();
formData.append("resume", file);
// Update the user record with the new resume
return await this.pb.collection("users").update(user.id, formData);
}
private getElements(): AuthElements & { loadingSkeleton: HTMLDivElement } { private getElements(): AuthElements & { loadingSkeleton: HTMLDivElement } {
// Get all required elements // Get all required elements
const loginButton = document.getElementById("contentLoginButton") as HTMLButtonElement; const loginButton = document.getElementById("contentLoginButton") as HTMLButtonElement;
@ -309,8 +341,9 @@ export class StoreAuth {
const officerView = document.getElementById("officerView"); const officerView = document.getElementById("officerView");
const mainTabs = document.querySelector(".tabs.tabs-boxed"); const mainTabs = document.querySelector(".tabs.tabs-boxed");
const officerContent = document.getElementById("officerContent"); const officerContent = document.getElementById("officerContent");
const settingsView = document.getElementById("settingsView");
if (defaultView && officerView && mainTabs && officerContent) { if (defaultView && officerView && mainTabs && officerContent && settingsView) {
// Show default view and its tabs // Show default view and its tabs
defaultView.classList.remove("hidden"); defaultView.classList.remove("hidden");
mainTabs.classList.remove("hidden"); mainTabs.classList.remove("hidden");