cookies() is not instant
Unanswered
Arinji posted this in #help-forum
ArinjiOP
Alright, so I have this Page
getModel function
Now if you paste this in the browser
"https://vibeify.xyz/verify?token=...." even with a valid cookie, its gonna take you to login.. but if you first open just /verify then put the token..it works?
Ping me :D
export const dynamic = "force-dynamic";
import { getModel } from "@/utils/getModel";
import { SendEmailButton } from "./buttons";
import Pocketbase from "pocketbase";
export default async function Page({
searchParams,
}: {
searchParams: { [token: string]: string | undefined };
}) {
const model = await getModel();
const pb = new Pocketbase(process.env.NEXT_PUBLIC_POCKETBASE_URL);
let isVerified = "null" as "null" | "true" | "false";
if (searchParams.token) {
try {
await pb.collection("users").confirmVerification(searchParams.token);
isVerified = "true";
} catch (e) {
isVerified = "false";
}
}
console.log(searchParams.token, isVerified);
return (
<div className="...">
<h1 className="...">
VERIFY
</h1>
<h2 className="...">
Verify your email to start using Listify!
</h2>
<div className="...">
<div className="">
{" "}
<h2 className="">
Current Email:
</h2>
</div>
<div className="h-full w-full shrink-0 md:w-[250px]">
<p className=" truncate text-center text-[20px] font-medium text-palette-primary">
{model!.email}
</p>
</div>
<div className="..">
<h2 className="...">
Not You?
</h2>
</div>
</div>
<SendEmailButton isVerified={isVerified} email={model!.email} />
</div>
);
}getModel function
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
export async function getModel() {
const cookie = cookies().get("pb_auth");
if (!cookie) redirect("/login");
const { model } = await JSON.parse(cookie.value);
return model;
}Now if you paste this in the browser
"https://vibeify.xyz/verify?token=...." even with a valid cookie, its gonna take you to login.. but if you first open just /verify then put the token..it works?
Ping me :D
1 Reply
ArinjiOP
bump