scrimba
Frontend Career Path
Advanced React
React Router
Cloud Firestore Setup 🔥
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Cloud Firestore Setup 🔥
Expand for more info
api.js
run
preview
console
export async function getVans(id) {
const url = id ? `/api/vans/${id}` : "/api/vans"
const res = await fetch(url)
if (!res.ok) {
throw {
message: "Failed to fetch vans",
statusText: res.statusText,
status: res.status
}
}
const data = await res.json()
return data.vans
}

export async function getHostVans(id) {
const url = id ? `/api/host/vans/${id}` : "/api/host/vans"
const res = await fetch(url)
if (!res.ok) {
throw {
message: "Failed to fetch vans",
statusText: res.statusText,
status: res.status
}
}
const data = await res.json()
return data.vans
}

export async function loginUser(creds) {
const res = await fetch("/api/login",
{ method: "post", body: JSON.stringify(creds) }
)
const data = await res.json()

if (!res.ok) {
throw {
message: data.message,
statusText: res.statusText,
status: res.status
}
}

return data
}
Console
/host/income
-6:04