auth syncing

This commit is contained in:
Ishaan Dey
2024-04-17 22:55:02 -04:00
parent a53cc57b24
commit 14d76c605e
2 changed files with 42 additions and 24 deletions

View File

@ -12,23 +12,24 @@ export default async function AppAuthLayout({
redirect("/")
}
const dbUser = await fetch(`http://localhost:8787/user?id=${user.id}`)
// const dbUserJSON = await dbUser.json()
const dbUser = await fetch(`http://localhost:8787/api/user?id=${user.id}`)
const dbUserJSON = await dbUser.json()
console.log(dbUser)
// if (!dbUserJSON) {
// const res = await fetch("http://localhost:8787/user", {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// },
// body: JSON.stringify({
// id: user.id,
// email: user.emailAddresses[0].emailAddress,
// }),
// })
// }
if (!dbUserJSON?.id) {
const res = await fetch("http://localhost:8787/api/user", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
id: user.id,
name: user.firstName + " " + user.lastName,
email: user.emailAddresses[0].emailAddress,
}),
})
} else {
// user already exists in db
}
return <>{children}</>
}