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
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- custom domain with CloudFlare
Hi all, it seems that CloudFlare has blocked cross-domain CNAME link which made my app hostname which is in CloudFlare, unable to create a CNAME pointing to clo...