
Hi all, I try to build a webapp which uses SSR and the Appwrite Auth to Login. I found some Templates which uses H3 for Session mgmt. But I can't get it to work with my middleware. Maybe someone did this already and can me push in the right direction. I use Pinia to save the User data after login in, but reload of cause the pinia store is cleared. It works only after direct login and handling of the middleware on client side. I have a middleware which checks if the session right now is not expired.
import { useUserStore } from "~/stores/userStore";
export default defineNuxtRouteMiddleware(async (to, from) => {
const authStore = useUserStore();
if (authStore.user) {
const sessionStatus = await authStore.checkSession(authStore.user.$id);
if (!sessionStatus) {
return navigateTo("/login");
}
} else {
return navigateTo("/login");
}
});
If this is more a Nuxt topic and wrong in this place. Im sorry and please close this.
Thanks a lot.

SSR is a million times more complicated. i highly suggest avoiding all of it if you can

if you really want to use SSR, the only resource i can provide is https://github.com/Meldiron/appwrite-ssr-nuxt. You'll have to read through and understand it...then see if you can apply it to middlewares

thanks a lot. this was really helpful. Now I understand, what the challenge is with ssr. Now I have to decided if it is worth it. π

Perhaps it is really bad, but i use client-sdk on server-side. I only have to create session as REST because i need to get cookies and then send cookies from server to client. Then with every request to server you get session in cookies. You will only have to set this session to appwrite request headers on server-side.

Client SDK server side is perfectly fine

Hi Otik, I still struggle to add auth with Appwrite to my Nuxt 3 app. Your approach sounds interesting. Do you have any repo where I can look at your approach?

Yes i made npm package for it. But today i will change many things there (i will text you here then) NPM package: appwrite-ssr
There you can see my example with sveltekit, but you can easly implement it to Nuxt3.

I dont have any repo you could see. But on appwrite-ssr you can find few examples. (!but how i have already said i will change it a little. I recommend you to wait, however if you download it now your code will work even in next version)


awesome I will have a look π

Now it should be all ok to use. If you consider to use it and will find any mistake send me a message (either email that is on site or discord) I even added repo that you could see how to implement it or you can use example codes on npm site.

Did you try?

sorry had no time till now. will look into it next week. π
Recommended threads
- "The document data is missing. Try again...
Hello, I am getting this error suddenly. I have been using this service for a year now, and I haven't made any changes to my code since then. My app was workin...
- Error: The document data is missing. Try...
I am not able to create any document on some of the collection/ DBs. As I can see many of us facing the same issue, need a quick resolution from the Appwrite Te...
- Appwrite Error: 401 Unauthorized on getC...
Hi everyone, I'm getting an error while trying to fetch the current user using Appwrite in my React project. Here's the error log: auth.js:41 GET https://fra....
