Make client components redirect server pages and do server actions.
Answered
D34dlyK1ss posted this in #help-forum
First of all I got the problem with forms not submitting and redirecting in one click.
Lastly, I want my forms in client components to redirect and clear cookies.
Lastly, I want my forms in client components to redirect and clear cookies.
Answered by Arinji
111 Replies
PageButton
JoinGameButton
LogoutButton
Logout function
redirects aren't working
and in the login page I have to click once to submit, then click again to redirect
@D34dlyK1ss this is a lot of code xD
can you send the specific ones which are broken
i already see one issue, redirect wont work in client components
@D34dlyK1ss LogoutButton
make onSubmit async, and await your logout() call,
also use this, its generally cleaner than the expires
https://nextjs.org/docs/app/api-reference/functions/cookies#cookiesdeletename
also use this, its generally cleaner than the expires
https://nextjs.org/docs/app/api-reference/functions/cookies#cookiesdeletename
@Arinji https://nextjs.org/docs/app/api-reference/functions/use-router
Use this
this was one of the issues, thanks
show login
you are redirecting in login right?
so
I am using middleware
but I am trying to redirect after I set the session
something must be happening between that redirect and my middleware
making the whole thing not work on first click
cant you just redirect after setting the session lol
@Arinji .....why
to avoid people from going to the login page
if the cookie exists
meaning that they're logged in already
@D34dlyK1ss to avoid people from going to the login page
seperation of concerns
let the middleware handle that liek you do already
let your login also redirect
that's what I am doing
but I have to click login twice
show your login function
@D34dlyK1ss Click to see attachment
you are only setting the session
add a redirect as well
did your dog eat the redirect :D
probably
@D34dlyK1ss probably
bring it back and lemme know if all your issues are fixed
I still have to click twice
sir
thats to fix the message one
lmao
forgot
right
1st problem solved
2nd
Logout isn't removing the cookie
I am using
cookie.delete nowand I am using
awaitshow logout
again
@D34dlyK1ss this is the function
await cookies().delete as well
pretty sure its a promise
makes sense
mhm :D
but that ain't it
200+ lines? XD
ok dont
do you have "use server" at the top?
yes
ok.... this is weird
are you sure its not deleting btw, like did you check in your application
ispect element -> application -> cookies
CTRL+F5 and it's still there
HMMMMMMMMMMMMMMMMMMMMmm
it's use to delete
but idk what I did for it to stop
can you do one thing
cookies().set("session", "test");
cookies().delete("session");
cookies().delete("session");
fix any typos i made
where
in the logout button?
yea in the logout function
hmmmmmmmm
i feel like we are doing a skill issue somewhere
factual
@D34dlyK1ss factual
do you have a github repo
nope, only my WS version of this app
I wanted to have the basics settled down first in Next.JS before uploading
hm
make a repo pls, i can check it out later when i have the tme
you'd have to create a MySQL database
forget about it
let someone else come here
probably because I set this to HTTP only?
@D34dlyK1ss let someone else come here
thas crazy but sure
@D34dlyK1ss probably because I set this to HTTP only?
shldnt really matter
and need to send a request to the Middleware?
all of a sudden it works
alright
and got everything I had an issue with fixed
thank you @Arinji for your help