Back

Handle sessions in a Nuxt 3 SSR app

  • 0
  • Self Hosted
  • Accounts
  • Web
  • Users
murru_AY23-04
1 Feb, 2024, 22:26

Hello there! So, I have a Nuxt 3 SSR app. I have a middleware for the "/" route that executes in process.server. This middleware uses the account.get() method to check the session of the user. If it doesn't exist any it redirects to the login page. This is working fine.

Then, I have my login page where I create the emailSession and then it redirects to the "/" route.

The thing is that if I reload in the "/" route, it redirects me again to the login page even if the session is already active on my appwrite console.

What am I doing wrong?

TL;DR
Developers are having trouble with session handling in a Nuxt 3 SSR app. They are using a middleware on the "/" route to check the user session, and if it doesn't exist, it redirects to the login page. However, when they reload on the "/" route, it still redirects them to the login page, even though the session is active in the appwrite console. Solution: It is suggested to change the project to full client-side rendering to avoid these issues. Additionally, in the next release (1.5) of Nuxt, there are plans for better SSR authentication and official examples.
Kenny
1 Feb, 2024, 22:30

You might check this out.

https://github.com/Meldiron/appwrite-ssr-nuxt

I believe it's not working for you since it's rendered server side, unless you've passed along that auth information it have no idea that you've authenticated client side?

murru_AY23-04
1 Feb, 2024, 22:44

Thank you! I’ll take a look at it and will update result here

murru_AY23-04
1 Feb, 2024, 22:49

I think I get it

Kenny
1 Feb, 2024, 22:49

I think in the next release 1.5 they're planning some better SSR auth, and providing official examples. But not sure the time frame on when 1.5 will release.

murru_AY23-04
1 Feb, 2024, 22:50

So, I have to create a custom domain here... Right? What if I'm working in my local machine?

murru_AY23-04
1 Feb, 2024, 22:56

This is awesome

murru_AY23-04
1 Feb, 2024, 22:56

Still, I think I might just change the project to full client side rendering just to avoid some future situations?

Kenny
1 Feb, 2024, 22:58

You can update your hosts file to have something like

127.0.0.1 domain.com

then in your nuxt.config.js file

TypeScript
server: {
    port: 3000,
    host: 'http://domain.com',
}

Then you can access it by going to

domain.com:3000

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