Back

get logged user from server-side - NextJs

  • 0
  • Users
  • Accounts
  • Web
abel_banze
28 Dec, 2023, 17:26

Guys, is there any approach to get current logged account from the server-side?

Developing with Nextjs

TL;DR
The user is asking if there's a way to get the currently logged in user from the server-side in Next.js. They mention considering using SSR and want to redirect to the login page before fully loading the homepage. Recommendations are made to either use JWT tokens or manually create a session server-side to extract the session cookie from the header. A link to a demo is provided. There is also a suggestion to consider doing it client-side instead of using SSR. The user insists on using SSR to get the author of a post and asks for any approaches to achieve their goal. No solution is provided in the thread.
abel_banze
28 Dec, 2023, 17:30

get logged user from server-side [NextJs]

abel_banze
28 Dec, 2023, 17:30

get logged user from server-side - NextJs

Ernest
28 Dec, 2023, 18:52
ideclon
28 Dec, 2023, 19:00

That wouldn’t help with “getting the currently logged in user”.

Drake
28 Dec, 2023, 20:42

do you really need SSR?

abel_banze
28 Dec, 2023, 20:47

Yes, I really do. I need it to get the author of a 'creation'. I mean, when someone create a post I need to get its account_id to set has the author of that post all of that in SSR

Drake
28 Dec, 2023, 20:54

but why do you need SSR? Why not turn off SSR and do it client side?

abel_banze
28 Dec, 2023, 21:05

It’s a personal choice, I’m new to the dev world. I think SSR is faster and more secure than CSR.

Also, using SSR will make it easier for me to redirect to the login page before fully loading the homepage. I’m developing my app using Next.js

Drake
28 Dec, 2023, 21:12

honestly, especially if you're new, i recommend staying away from SSR because it adds complexity.

if you really want to continue using SSR, you'll either need to use JWT tokens or manually create a session server side so you can extract the session cookie from the header and fully manage it yourself (demo: https://next-js.ssr.almostapps.eu/).

We do have plans to improve SSR with Appwrite which can be found here: https://github.com/appwrite/rfc/pull/59

abel_banze
28 Dec, 2023, 21:15

I’ll take on SSR, who knows, maybe with this challenge I’ll learn faster 😅 . Thank you for the tips, I’ll take a look.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more