mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-09 17:52:14 +00:00
feat: ssr fetch details
This commit is contained in:
parent
1226f34a54
commit
b7225ad550
2 changed files with 31 additions and 17 deletions
|
|
@ -5,6 +5,8 @@ export const handleFetch: HandleFetch = async ({ request, fetch, event,}) => {
|
||||||
|
|
||||||
const cookie = event.request.headers.get('cookie') || '';
|
const cookie = event.request.headers.get('cookie') || '';
|
||||||
|
|
||||||
|
console.log(`SSR: handleFetch() cookie: ${cookie}`);
|
||||||
|
|
||||||
request.headers.set('cookie', cookie);
|
request.headers.set('cookie', cookie);
|
||||||
|
|
||||||
request.headers.append('Origin', event.url.origin);
|
request.headers.append('Origin', event.url.origin);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,35 @@ import type { CandidateData, CandidateLogin } from '$lib/stores/candidate';
|
||||||
import type { SubmissionProgress } from '$lib/stores/portfolio';
|
import type { SubmissionProgress } from '$lib/stores/portfolio';
|
||||||
import { API_URL, errorHandler } from '.';
|
import { API_URL, errorHandler } from '.';
|
||||||
|
|
||||||
|
|
||||||
|
// SSR Compatible
|
||||||
|
export const apiLogout = async (fetchSsr?: any) => {
|
||||||
|
try {
|
||||||
|
fetchSsr ? await fetchSsr(API_URL + '/candidate/logout', { method: 'POST', credentials: 'include' }) : await axios.post(API_URL + '/candidate/logout', { withCredentials: true });
|
||||||
|
} catch (e: any) {
|
||||||
|
throw errorHandler(e, 'Logout failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SSR Compatible
|
||||||
|
export const apiFetchDetails = async (fetchSsr?: any): Promise<CandidateData | null> => {
|
||||||
|
try {
|
||||||
|
if (fetchSsr) {
|
||||||
|
const res = await fetchSsr(API_URL + '/candidate/details', { method: "GET", credentials: 'include' });
|
||||||
|
const body = await res.text();
|
||||||
|
console.log(body);
|
||||||
|
if (res.status === 500) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSON.parse(body);
|
||||||
|
}
|
||||||
|
const res = await axios.get(API_URL + '/candidate/details', { withCredentials: true });
|
||||||
|
return res.data;
|
||||||
|
} catch (e: any) {
|
||||||
|
throw errorHandler(e, 'Failed to fill details');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const apiWhoami = async (): Promise<string> => {
|
export const apiWhoami = async (): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${API_URL}/whoami`);
|
const res = await axios.get(`${API_URL}/whoami`);
|
||||||
|
|
@ -21,14 +50,6 @@ export const apiLogin = async (data: CandidateLogin): Promise<number> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
export const apiLogout = async (fetchSsr?: any) => {
|
|
||||||
try {
|
|
||||||
fetchSsr ? await fetchSsr(API_URL + '/candidate/logout', { method: 'POST', credentials: 'include' }) : await axios.post(API_URL + '/candidate/logout', { withCredentials: true });
|
|
||||||
} catch (e: any) {
|
|
||||||
throw errorHandler(e, 'Logout failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const apiFillDetails = async (data: CandidateData): Promise<CandidateData> => {
|
export const apiFillDetails = async (data: CandidateData): Promise<CandidateData> => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|
@ -40,15 +61,6 @@ export const apiFillDetails = async (data: CandidateData): Promise<CandidateData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const apiFetchDetails = async (): Promise<CandidateData> => {
|
|
||||||
try {
|
|
||||||
const res = await axios.get(API_URL + '/candidate/details', { withCredentials: true });
|
|
||||||
return res.data;
|
|
||||||
} catch (e: any) {
|
|
||||||
throw errorHandler(e, 'Failed to fill details');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const apiFetchSubmissionProgress = async (): Promise<SubmissionProgress> => {
|
export const apiFetchSubmissionProgress = async (): Promise<SubmissionProgress> => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(API_URL + '/candidate/portfolio/submission_progress', { withCredentials: true });
|
const res = await axios.get(API_URL + '/candidate/portfolio/submission_progress', { withCredentials: true });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue