0

I've created an "Email Session" & store the session id, which I get in return. Then when again I use the same session id with the following "getSession()" method, I get the below error.

const promise = account.getSession("64d3b0ab0ae91ad7c150");

promise.then(
  function (response) {
    console.log("user session info: ", response); // Success
  },
  function (error) {
    console.log("user session error: ", error); // Failure
  }
);

Error getting - a

What exactly I'm doing wrong here? Need some guidance.

Suresh
  • 5,687
  • 12
  • 51
  • 80

1 Answers1

0

Are you using Qwik and server-side rendering? Is the email session being created server-side? If so, the session isn't being persisted since Appwrite uses Cookies to maintain sessions, but the cookies aren't automatically handled server-side like they are when in a browser.

To get it to work, you'll have to:

  1. Set up a custom domain for appwrite so that your appwrite endpoint is a subdomain of your app (e.g. appwrite.example.com and example.com).
  2. Manually create an email session server-side.
  3. Extract the cookie from the response headers.
  4. Set the cookie so that it is passed to the client and can be used client-side
  5. For future server-side API calls, extract the session from the cookie and include it in the request to Appwrite.

For an example, check out this demo: https://github.com/Meldiron/appwrite-ssr-qwik#-so-how-does-it-work.

Steven Nguyen
  • 452
  • 4
  • 4