Skip to content

Commit

Permalink
chore: Add tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayan-724 committed Sep 14, 2024
1 parent 7300a88 commit 098ec1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 9 additions & 3 deletions crates/backend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ pub fn get_device_id(req: &worker::Request) -> Option<String> {
.ok()
.flatten()
.or_else(|| req.headers().get("x-forwarded-for").ok().flatten())
.or_else(|| req.cf().and_then(|cf| cf.city()))?;
.or_else(|| req.cf().and_then(|cf| cf.city()))
.inspect(|x| worker::console_log!("DeviceID-SiteID: {x:?}"))?;

let user_agent = req.headers().get("user-agent").ok().flatten()?;
let user_agent = req
.headers()
.get("user-agent")
.ok()
.flatten()
.inspect(|x| worker::console_log!("DeviceID-UserAgent: {x:?}"))?;

worker::console_log!("{site_id} + {user_agent}");
worker::console_log!("DeviceID: {site_id} + {user_agent}");

Some(site_id + &user_agent)
}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/routes/form/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export async function load(
console.log(`Loading form ${params.slug} from: ${FORM_URL}`);
const form_res = await fetch(FORM_URL);
const form = await form_res.json() as ApiResponse<Form>;
console.log("Form loaded:", form);

if (form.success) {
const code = cookies.get("external-code");
console.log("User has code: ", !!code)

if (form.data.require_login && !code) {
return {
Expand All @@ -31,6 +33,7 @@ export async function load(
};
}

console.log(`Loading session from: ${FORM_URL}/session`);
const session_res = await fetch(`${FORM_URL}/session`, {
headers: code
? {
Expand All @@ -40,6 +43,7 @@ export async function load(
});

const session = await session_res.json() as ApiResponse<string>;
console.log("Session loaded:", session);

if (session.success) {
const user = session.data!;
Expand All @@ -65,10 +69,10 @@ export async function load(
user,
answers: [],
};
}

if (session_res.status === 403) {
} else if (session_res.status === 403) {
return error(session_res.status, "Already answered");
} else if (!session.success) {
return error(session_res.status, session.errors[0]);
}

return {
Expand Down

0 comments on commit 098ec1d

Please sign in to comment.