SolidJSS
SolidJSโ€ข3y agoโ€ข
2 replies
lars

Confusion around solid-query

coming from Angular, so I'm new to both solidJS and solid-query/react-query,

when writing a useAuth hook, how would you go about fetching and storing the initial session?

export const useAuth = () => {
  const [session, setSession] = createSignal<Session | null>(null);

  /** Instance of auth client. */
  const { auth } = createClient();

  const initialSession = () => {
    return createQuery({
      queryKey: () => ['getSession'],
      queryFn: () => auth.getSession().then(res => res.session),
    });
  };

  setSession(initialSession()?.data ?? null); // <- this doesn't work as expected
  
  return { session }
}
Was this page helpful?