1
import { CHECK_USER_ROUTE } from "@/utils/ApiRoutes";
import { firebaseAuth } from "@/utils/FirebaseConfig";
import axios from "axios";
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import Image from "next/image";
import { useRouter } from "next/router";
import React from "react";
import {FcGoogle} from "react-icons/fc";

function login() {
const router = useRouter()
const handleLogin = async () => {
const provider = new GoogleAuthProvider();
const {user:{displayName:name,email,photoUrl:profileImage},} = await      signInWithPopup(firebaseAuth,provider);
try {
if(email) {
const {data} = await axios.post(CHECK_USER_ROUTE,{email});
console.log({data});
if(!data.status){
router.push("/onboarding");
}
}
} catch (err) {
console.log(err);
}
};
return( <div className="flex justify-center items-center bg-panel-header-background h-screen w-   screen flex-col gap-6">
<div className="flex items-center justify-center gap-2 text-white">
<Image src="/whatsapp.gif" alt="Whatsapp" height={300} width={300}/>
<span className="text-7xl">Whatsapp</span>
</div>
<button className="flex items-center justify-center gap-7 bg-search-input-container-background p-5 rounded-lg"onClick={handleLogin}>
<FcGoogle className="text-4xl"/>
<span className="text-white text-2xl">Login with Google</span>
</button>
</div>
)
}

export default login;

This is my code. I am working on a chat application.When i console.log the data I dont get the actual data instead I get error as AxiosError as well as an Internal Server Error.

The AxiosError : AxiosError code : "ERR_BAD_RESPONSE" config : {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …} message : "Request failed with status code 500" name : "AxiosError" request : XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} response : {data: '\n\n\n<meta char…lib\router\index.js:47:12)\n\n\n', status: 500, statusText: 'Internal Server Error', headers: AxiosHeaders, config: {…}, …} stack : "AxiosError: Request failed with status code 500\n at settle (webpack-internal:///./node_modules/axios/lib/core/settle.js:24:12)\n at XMLHttpRequest.onloadend (webpack-internal:///./node_modules/axios/lib/adapters/xhr.js:125:66)" [[Prototype]] : Error Internal Server Error : POST http://localhost:3005/api/auth/check-user 500 (Internal Server Error)enter image description here

I don't know how to solve it. This is how I expect to get the result.enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.