When the user wants to connect with an expert, they submit data in the below format.
SearchTalent.js
component
const handleSubmit = async () => {
const loginState = localStorage.getItem("authenticated");
let uploads = await uploadSelectedFiles();
const saveData = {
// taskName: taskName,
description: description,
loomLink: loomLink,
uploadFiles: uploads,
expertCategories: expertCategories,
post_userid: currentUserUid,
posterRole: myRole,
timestamp: serverTimestamp(),
};
if (loginState == "true") {
setLoader(true);
let newJobId = await writeJobPostToDb(saveData);
console.log(newJobId, "this is a hilarious jobid");
// Get the updated document from Firestore to access the actual timestamp
sendNewJobNotify(newJobId, skillSet, expertCategories);
navigate(`/Portfolio/id=${currentUserUid}/order-history`);
localStorage.removeItem("jobPostData");
} else {
// localStorage.setItem("taskName", JSON.stringify(taskName));
localStorage.setItem(
"expertCategories",
JSON.stringify(expertCategories)
);
//navigate(`/Portfolio/id=${currentUserUid}/order-history`);
localStorage.setItem("jobPostData", JSON.stringify(saveData));
navigate("./register");
}
};
common.js
utils
export const writeJobPostToDb = async (data) => {
const docRef = await addDoc(collection(db, "jobpost"), data);
return docRef.id;
};
Customers post their requirements to find out the experts and those data are stored on the Firestore. It works as normal when the user logged in, but it doesn’t log the timestamps correctly when the user is not logged in.
In normal, it should be like this.
timestamp
September 2, 2024 at 10:19:56 AM UTC-7
But seeing this on the jobpost data that created before the user Signup to the platform.
timestamp (map)
_methodName: "serverTimestamp" (string)
The whole jobpost
collection field looks like this.
description: "" (string)
expertCategories: (array)
0 "Nuke" (string)
loomLink: "" (string)
post_userid: "v7mCJl07XLO3kQL6AWC7" (string)
posterRole: ""(string)
timestamp: (map)
_methodName: "serverTimestamp" (string)
uploadFiles
Other fields are fine, but only the timestamp not working.
I’ve checked the Firestore rule setup, and asyc/await till the DB update and I was able to reproduce this by triggering the handleSubmit
without Login/Signup to the platform.
First time visiters of the website can also create the jobpost
by triggering handleSubmit
, and they will be redirecting to the register
page first. Temporary jobpost
data created by the user before Signup, first stored on the localStorage
.
I changed above code to this and solve the issue temporarily.
const handleSubmit = async () => {
const loginState = localStorage.getItem("authenticated");
if (loginState == "true") {
let uploads = await uploadSelectedFiles();
const saveData = {
description: description,
loomLink: loomLink,
uploadFiles: uploads,
expertCategories: expertCategories,
post_userid: currentUserUid,
posterRole: myRole,
timestamp: serverTimestamp(),
};
setLoader(true);
let newJobId = await writeJobPostToDb(saveData);
sendNewJobNotify(newJobId, skillSet, expertCategories);
navigate(`/Portfolio/id=${currentUserUid}/order-history`);
localStorage.removeItem("jobPostData");
} else {
localStorage.setItem(
"expertCategories",
JSON.stringify(expertCategories)
);
navigate("./register");
}
};
App.js
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout onlogin={isLoggedIn} />}>
<Route path="/login" element={<Login />} />
<Route index element={<Home />} />
<Route element={<PrivateRoute />}>
<Route path="/order-instant" element={<SearchTalent />} />
Home.js
component
function Home() {
return (
<div className="flex w-full p-0 sm:p-6 px-auto">
<SearchTalent />
I am using the Firebase SDK version ^9.23.0
Has anyone else encountered this issue? I really hop for some assistance on this!
7
You can instead use firebase.firestore.TimeStamp.now().toDate()
to get a similar result.
https://firebase.google.com/docs/reference/js/v8/firebase.firestore.Timestamp
end result will look like this 2024-09-25T06:50:47.426Z
3