In Next.js during SSR I get user object from session and ip address of client that performed request.
return {
props: {
user,
ipAddress,
},
};
User can exist but it can also be undefined if request is unauthenticated. I want to be able to:
- If user is authenticated run react-query hook that uses
user.idand fetches user settings. - If user is not authenticated provide default settings values that I have stored in config file.
const LandingPage = ({
user,
ipAddress,
}: LandingPageProperties): JSX.Element => {
// User exist
const { config } = useGetOwnSettingsQuery(
{
endpoint: 'http://localhost:3000/api/graphql',
fetchParams: {
headers: setFetchHeaders(),
},
},
{ userWhere: { id: user?.id } },
);
// User does not exist
imported config from config.ts
return <LandingPageMap className="map" { config goes here }/>;
};
I really dont have good idea how to perform what I want, hooks do not like if I call them inside useEffect and they dont like if I return early to check if user exist.