See AuthWrapperProps.
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>
);
}
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 GETsNEXT_PUBLIC_EMAIL_AUTH_ENDPOINTwith credentials; the plain-text response body is the access token (empty when logged out), stored and provided to children.Must be placed above
ApolloWrapperin the component tree (sinceApolloWrapperneeds the token).The same name exported from
naystack/authis 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".