Hello I don’t understand why I don’t see the data in my db, do you have any idea?
route.jsx
import { db } from "@/config/db";
import { Users } from "@/config/schema";
import { NextResponse } from "next/server";
export async function POST(req) {
const { user } = await req.json();
try {
const userInfo = await db.select().from(Users)
.where(eq(Users.email, user?.primaryEmailAdress.emailAdress))
console.log("User", userInfo);
if (userInfo?.length == 0) {
const SaveResult = await db.insert(Users)
.values({
name: user?.fullName,
email: user?.primaryEmailAddress.emailAddress,
imageUrl: user?.imageUrl,
}).returning({ Users })
return NextResponse.json({ 'result': SaveResult[0].Users })
}
return NextResponse.json({ 'result': userInfo[0] })
}
catch (e) {
return NextResponse.json({ error: e })
}
}
provider.js
"use client"
import { useUser } from '@clerk/nextjs'
import axios from 'axios';
import React, { useEffect } from 'react'
function Provider({ children }) {
const { user } = useUser();
useEffect(() => {
user && VerifyUser();
}, [user])
const VerifyUser = async () => {
const dataResult = await axios.post('/api/verify-user', {
user: user
});
console.log(dataResult.data)
}
return (
<div>
{children}
</div>
)
}