Next.js Discord

Discord Forum

Client and Server side page

Unanswered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
Can somebody explain how would i do this in next
user goes to sign up page,
if server gets a cookie makes a request and the request is OK they get redirected
else: give them a client page with usestates

8 Replies

@Peterbald Can somebody explain how would i do this in next user goes to sign up page, if server gets a cookie makes a request and the request is OK they get redirected else: give them a client page with usestates
// app/sign-up/page.tsx
export default function Page() {
  const token = cookies().get('token');
  const session = getSession(token);
  if (session) redirect('/dashboard');
  return <SignUpPage />
}

"use client";
export default function SignUpPage() {
  const [email, setEmail] = useState('');
  ...
}
PeterbaldOP
what if it is a http only cookie?
exact same code applies
such cookies are not accessible in client-side javascript, but here we are accessing them in server components so they are accessible as usual
PeterbaldOP
hmm
@joulev such cookies are not accessible in client-side javascript, but here we are accessing them in server components so they are accessible as usual
PeterbaldOP
ok so i have the cookie from the set-cookie header but how can i persist this server side and client side at the same time I know this sounds really strange and kind of stupid
but i need to check sometimes so I can SSR but also use it as part of client req
what do you mean? i dont understand this question