hello this is my code backend side of my schemaTypes file
import { defineType, defineField } from "sanity";
export const schemaTypes=
[
defineType({
name:'comment',
title:'Comment',
type:'document',
fields:[
defineField(
{
name:"postedBy",
title:"PostedBy",
type:"postedBy"
}),
defineField({
name:"comment",
title:"Comment",
type:"string"
})
]
}),
defineType(
{
name:'user',
title:"User",
type:"document",
fields:[
defineField(
{
name:'userName',
title:"UserName",
type:"string"
}),
defineField({
name:'image',
title:"Image",
type:"string"
}),
]
}),
defineType({
name:"postedBy",
title:"PostedBy",
type:"reference",
to:[
{
type:"user"
}
]
}),
defineType({
name:"pin",
title:"Pin",
type:"document",
fields:[defineField(
{
name:"title",
title:"Title",
type:"string"
}),
defineField({
name:"about",
title:"About",
type:"string"
}),
defineField({
name:"destination",
title:"Destination",
type:"url"
}),
defineField({
name:"category",
title:"Category",
type:"string"
}),
defineField({
name:"image",
title:"Image",
type:"image",
options:{
hotspot:true
}
}),
defineField({
name:"userId",
title:"UserId",
type:"string"
}),
defineField({
name:"postedBy",
title:"PostedBy",
type:"postedBy"
}),
defineField({
name:"save",
title:"Save",
type:"array",
of:[{type:'save'}]
}),
defineField({
name:"comments",
title:"Comments",
type:"array",
of:[{type:'comment'}]
})
]
}),
defineType({
name:'save',
title:'Save',
type:'document',
fields:[
defineField({
name:"postedBy",
title:"PostedBy",
type:"postedBy"
}),
defineField({
name:"userId",
title:"UserId",
type:"string"
})
]
}),
]
and this is my client.js file code
import {createClient} from "@sanity/client"
import imageUrlBuilder from "@sanity/image-url"
export default function test(){
}
export const client=()=>createClient({
projectId:process.env.REACT_APP_SANITY_PROJECT_ID,
dataset: 'production',
apiVersion: '2023-03-17',
useCdn:true,
token:process.env.REACT_APP_SANITY_TOKEN,
})
const builder = imageUrlBuilder(client)
export const urlFor=(source)=>builder.image(source)
and this is my client side code: login page first
import React from 'react'
import { useEffect, useState } from 'react'
import {useNavigate} from "react-router-dom"
import {FcGoogle} from "react-icons/fc"
import shareVideo from "../assets/share.mp4"
import logo from "../assets/logowhite.png"
import jwt_decode from "jwt-decode"
import {client} from "../client"
import {urlFor} from "../client"
console.log(urlFor)
console.log(client)
const Login = () => {
const navigate = useNavigate()
//const [user,setUser]=useState({})
function handleCallbackResponse(response){
var userObject=jwt_decode(response.credential)
console.log(userObject)
//setUser(userObject)
localStorage.setItem('user',JSON.stringify(userObject))
const {name,nbf,picture}=userObject
const doc={
_id:nbf,
_type:'user',
userName:name,
image:picture
}
client.createIfNotExists(doc)
.then(()=>{
navigate('/',{replace:true})
}).catch(err=>console.log("error creating"));
}
useEffect(()=>{
window.google.accounts.id.initialize({
client_id:process.env.REACT_APP_GOOGLE_API_TOKEN,
callback:handleCallbackResponse
})
window.google.accounts.id.renderButton(document.getElementById('signInDiv'),
{theme: "outline", size:"large"}
)
})
const responseGoogle=(response)=>{
}
return (
<div className="flex justify-start items-center flex-col h-screen">Login
<div className ="relative w-full h-full">
<video
src={shareVideo}
type="video/mp4"
loop
controls={false}
muted
autoPlay
className="w-full h-full object-cover"
/>
<div className="absolute flex flex-col justify-center items-center top-0 right-0 left-0 bottom-0 bg-blackOverlay">
<div className='p-5'>
<img src={logo} width="130px" alt="logo"/>
</div>
<div className='shadow-2xl'>
<button
id="signInDiv"
type="button"
className='bg-mainColor flex justify-center items-center p-3 rounded-lg cursor-pointer outline-none'
>
<FcGoogle className='mr-4'
/>Sign in with google
</button>
</div>
</div>
</div>
</div>
)
}
export default Login
and then my home page wich should be redirected to from login page
I am getting this error when I choose the google mail I want to log in with
client__WEBPACK_IMPORTED_MODULE_4_.client.createIfNotExists is not a function
So from the first look I think I have a problem in my client file can someone help me
I think the problem is in client.js file on the part of createClient() function