I've been trying to improve my React skills by following some JavaScript Mastery tutorials, but it happened that one of them is out of date. In the tutorial, he uses the old Google Login, which I could update, the problem is the fix to the Sanity.io that he reccomends is made using a totally different application and typescript(I started the project using JavaScript, and would like to finish it innit). That been said, how could I connect the Google Login button information(which works, but don't get the data) and transfer it to Sanity.io?
Login code:
import React from "react"; import { useNavigate } from
"react-router-dom"; import { GoogleOAuthProvider } from
"@react-oauth/google"; import { GoogleLogin, googleLogout } from
"@react-oauth/google"; import { FcGoogle } from "react-icons/fc";
import covenlogin from "../assets/covenlogin.mp4"; import logo from
"../assets/logo.png"; import { gapi } from "gapi-script"; import {
useEffect } from "react";
import { client } from "../client";
const Login = () => { const navigate = useNavigate();
const responseGoogle = (response) => {
localStorage.setItem("user", JSON.stringify(response.profileObj));
const { name, googleId, imageUrl } = response.profileObj; const doc = { _id: googleId, _type: "user", userName: name, image: imageUrl, }; client.createIfNotExists(doc).then(() => { navigate("/", { replace: true }); }); };
return (
<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" /> </div> <div className="shadow-2xl"> <GoogleLogin onSuccess={responseGoogle} onError={responseGoogle} /> </div> </div> </div> </div> ); }; export default Login;
User schema code:
export default {
name: 'user', title: 'User', type: 'document', fields: [ { name: 'userName', title: 'UserName',
type: 'string' }, { name: 'image', title: 'Image', type: 'string' }, ] }
PS: Also need to get the GoogleId, thanks for the reading.