After updating a user object, the new data is not immediately reflected in my NextJS 14 app #4920
Unanswered
akkisagiraju
asked this question in
Q&A
Replies: 1 comment
-
Here's the login route. import db from "@/lib/db"
import { cookies } from "next/headers"
import { NextResponse } from "next/server"
export async function POST(request: Request) {
try {
const { email, password } = await request.json()
const result = await db.authenticate(email, password)
const { record, token } = result
record.token = token
cookies().set("pb_auth", db.client.authStore.exportToCookie())
return NextResponse.json(record)
} catch (err: any) {
return new Response(
JSON.stringify({ error: err.message || err.toString() }),
{
status: 500,
headers: {
"Content-Type": "application/json",
},
}
)
}
} And this how I'm getting the currentUser to pass the object to the import { getCurrentUser } from "@/lib/session"
import { DashboardHeader } from "@/components/header"
import { DashboardShell } from "@/components/shell"
import { UserNameForm } from "@/components/user-name-form"
export const metadata = {
title: "Settings",
description: "Manage account and website settings.",
}
export default async function SettingsPage() {
const user = await getCurrentUser()
return (
<DashboardShell>
<DashboardHeader
heading="Settings"
text="Manage account and website settings."
/>
<div className="grid gap-10">
<UserNameForm user={{ id: user.id, name: user.name || "" }} />
</div>
</DashboardShell>
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I'm using PocketBase as the backend for my NextJS 14 app. I'm using the
app
router in my project.Here's the problem. Whenever I enter a new
name
in the input field and submit the form, the patch request is successfully processed and I can see that the value is actually updated on the admin panel. But the cookie stored in the browser has the old data and as a resultgetCurrentUser()
is returning the old data of the user.The relevant pieces of my code:
app/api/users/[userId]/route.ts
lib/session.ts
lib/db.ts
This is the form on the UI
Please help me fix this.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions