OrJDev/create-jd-app

`useSession` doesn't work with CSR

kingstarfly opened this issue · 6 comments

image

Expectation: The app tells me that I'm logged in as a user by showing me "Logged in as XXXX"
Situation: Username is blank.

Steps to reproduce

  1. Create new project with auth and prisma selected.
  2. Add discord client id and secret into .env file.
  3. Click log out.
  4. Click log in and go through Discord's OAuth client.
  5. Arriving at localhost:3000, the username is missing.

It seems like sessionData() isn't working as expected. Is this an issue with @auth/solid-start from the Auth.js library? Any help would be appreciated.

I had a similar issue with SSR set to false, if it's set to true the issue goes away. That said with SSR set to false and being logged in, you can still access your session via TRPC context if you make an endpoint for it.

I also have the same issue with ssr set to false in solid's vite plugin and using createServerData$. I'm unsure if createServerData$ is supposed to work when you have no ssr? If I have this code:

function serverData() {
  return createServerData$(async () => {
    const res = await fetch("https://hogwarts.deno.dev/students");

    return await res.json();
  });
}
export const B = () => {
  const b = serverData();
  return (
    <Show when={serverData()} fallback={<div>No serverdata</div>}>
      <pre>{JSON.stringify(b())}</pre>
    </Show>
  );
};

then JSON.stringiy(b()) will return me
<!DOCTYPE html><html ><body ><script type=\"module\" src=\"/@vite/client\"></script><script type=\"module\" async src=\".....path-to-entry-client.tsx\"></script></body></html>

With ssr set to true I get the expected value back: [{"name":"Harry Potter"},{"name":"Ron Weasley"}]

server$ will not work when using client side rendering, therefore the session will not be passed correctly to the client, i have a pending pr that is supposed to add a createSession hook for @auth/solid-start, this hook will return the current logged in user from the client side only, just like the useSession hook of next-auth.

waiting for this pr to get merged - nextauthjs/next-auth#6795
and then i will modify create jd app to use the createSession hook aswell, this would work for both ssr & csr.

Takes time to get it merged in, would it matter to you if i made a separate package published under my name where i would push auth changes? Or do you want to wait for this to get merged

OrJDev commented

This was fixed in the latest release