naystack - v1.9.9
    Preparing search index...

    Function AuthWrapper

    • Provider that fetches the current access token from your auth endpoint and exposes it via TokenContext. Wrap your app (or the part that needs auth) so that useToken(), useLogin(), useSignUp(), useLogout() work. On mount it GETs NEXT_PUBLIC_EMAIL_AUTH_ENDPOINT with credentials; the plain-text response body is the access token (empty when logged out), stored and provided to children.

      Must be placed above ApolloWrapper in the component tree (since ApolloWrapper needs the token).

      The same name exported from naystack/auth is a Server Component version that performs that first fetch during SSR (forwarding the refresh cookie) and streams the token down, so the page doesn't wait for a client round-trip. Use it in a server layout; use this one anywhere that is already "use client".

      Parameters

      Returns Element

      TokenContext.Provider wrapping children.

      // app/layout.tsx
      import { AuthWrapper } from "naystack/auth/client";
      import { ApolloWrapper } from "naystack/graphql/client";

      export default function RootLayout({ children }: { children: React.ReactNode }) {
      return (
      <html lang="en">
      <body>
      <AuthWrapper>
      <ApolloWrapper>{children}</ApolloWrapper>
      </AuthWrapper>
      </body>
      </html>
      );
      }