Untitled
async getCaptcha() { try { const response = await axiosInstance.get("api/recruitment/candidate/get-captcha/", { withCredentials: true }); this.captchaImage = response.data.captcha_image; this.captchaText = response.data.captcha_text; const setCookieHeader = response.headers["set-cookie"]; if (setCookieHeader && setCookieHeader[0]) { const match = setCookieHeader[0].match(/sessionid=([^;]+)/); if (match) { this.sessionId = match[1]; console.log("Extracted session ID:", this.sessionId); } } const cookies = document.cookie; console.log("Cookies after captcha:", cookies); console.log("Cookies after getCaptcha:", document.cookie); return response.data; } catch (error) { console.error("Error fetching CAPTCHA:", error); throw error; } }, async register(data: RegisterForm) { this.loading = true; this.error = null; console.log("Cookies before register:", document.cookie); console.log("Using session ID:", this.sessionId); try { const registerData = { ...data, captchaText: this.captchaText }; const response = await axiosInstance.post( "api/recruitment/candidate/register/", registerData, { withCredentials: true, headers: { "Content-Type": "application/json", }, } ); if (response.status === 201) { this.user = response.data; this.isRegistered = true; this.noCandidate = response.data?.no_candidate || null; return response.data; } } catch (err: any) { console.error("Registration error:", err); if (err.response) { this.error = err.response.data?.message || `Error ${err.response.status}: ${err.response.statusText}`; } else if (err.request) { this.error = "No response received from the server. Please check your internet connection."; } else { this.error = err.message || "An unexpected error occurred."; } throw err; } finally { this.loading = false; } },
Leave a Comment