Cookies not saving
Answered
Blue Picardy Spaniel posted this in #help-forum
Blue Picardy SpanielOP
I'm having issues with my cookies not saving. See attached video
Fyi I'm using a proxy in nextjs and axios to make requests to my backend server which is hosted on port 3001 and everything was working fine before I started doing that
Fyi I'm using a proxy in nextjs and axios to make requests to my backend server which is hosted on port 3001 and everything was working fine before I started doing that
Answered by riský
if you dont specify expiry of cookie/token its defaulted to session, so set expiry for it
18 Replies
@Blue Picardy Spaniel I'm having issues with my cookies not saving. See attached video
Fyi I'm using a proxy in nextjs and axios to make requests to my backend server which is hosted on port 3001 and everything was working fine before I started doing that
if you dont specify expiry of cookie/token its defaulted to session, so set expiry for it
Answer
@riský if you dont specify expiry of cookie/token its defaulted to session, so set expiry for it
Blue Picardy SpanielOP
oh no way.. thank you!!<3
np, let me know when you change that and if there are any more issues :)
@riský np, let me know when you change that and if there are any more issues :)
Blue Picardy SpanielOP
fixed!!
yayy, sounds good!
Blue Picardy SpanielOP
@riský btw how do i remove cookies on the client?
"use client";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
function logOut() {
}
export default function LogOut() {
return (
<DropdownMenuItem onClick={logOut} className="cursor-pointer">Log Out</DropdownMenuItem>
);
}if its httpOnly, you cant on client but you can use simple server action that deletes and redirects to home
if its normal (which it tbh shouldnt for token), you can set it to something with expiry in past
Blue Picardy SpanielOP
yeah its httponly
can i just make a server function in the same component?
eg:
"use client";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
function logOut() {
"use server";
// remove cookie
}
export default function LogOut() {
return (
<DropdownMenuItem onClick={logOut} className="cursor-pointer">Log Out</DropdownMenuItem>
);
}its client, so make a "actions.ts" and export async function (only server comp can inline, but i tbh dont use that)
Blue Picardy SpanielOP
do you have docs for actions?
not on me, but google search for server actions should show what you need
Blue Picardy SpanielOP
how come you have to put use server if all components are automatically server components
page.tsx is default server, and anything you import is server, but once you define client boundry everything imported into it is client
Blue Picardy SpanielOP
ahh okay