Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to use useAuth with apollo client and nextjs #74

Open
chiptus opened this issue Apr 23, 2020 · 4 comments
Open

trying to use useAuth with apollo client and nextjs #74

chiptus opened this issue Apr 23, 2020 · 4 comments

Comments

@chiptus
Copy link

chiptus commented Apr 23, 2020

thanks for this work!

I'm trying to integrate useAuth with ApolloClient and nextjs.
I started from the code provided in the nextjs example, and now I'm adding Apollo. The client needs the access token so I'm did something like this:

export default function App({ Component, pageProps }) {
  const router = useRouter();
  return (
    <AuthProvider
      navigate={router.push}
      auth0_domain="..."
      auth0_client_id="..."
    >
      <ApolloWrapper>
        <Component {...pageProps} />
      </ApolloWrapper>
    </AuthProvider>
  );
}

// eslint-disable-next-line react/prop-types
function ApolloWrapper({ children }) {
  const { authResult, isAuthenticating, isAuthenticated } = useAuth();
  console.log({
    authResult,
    isAuthenticating,
    isAuthenticated: isAuthenticated(),
  });
  const client = createApolloClient(authResult && authResult.idToken);
  return <ApolloProvider client={client}>{children}</ApolloProvider>;
}

it works as long I'm staying in the app.
for some reason when I refresh the page (I disabled ublock), authResult becomes null and I can't send any request to the db (fails because missing access token)

@chiptus
Copy link
Author

chiptus commented Apr 23, 2020

oh, isAuthenticated is true, and I can see the logged in username, but authResult is undefined

@flybayer
Copy link

@chiptus did you get this working? I'm having the same problem

@chiptus
Copy link
Author

chiptus commented Jul 27, 2020

no, I moved to auth0/auth0-nextjs library, although I'm not sure I like it :D

@flybayer
Copy link

I found out the issue for me was that we were still using the default social login dev credentials. email/password worked fine, but not social login until we added our own social login keys to auth0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants