title: How to send httponly cookies client side when using next-auth credentials provider?
body: <p>I'm creating a next js application, using next-auth to handle authentication.</p>
  <p>I have an external backend api, so I'm using Credentials Provider.</p>
  <p>The problem is that the backend sends httponly cookies, but those are not being attached to the browser when i make a request client side.</p>
  <p>In /pages/api/[...auth].js</p>
  <pre class="lang-js prettyprint-override"><code>import NextAuth from 'next-auth';
  import Providers from 'next-auth/providers';
  import clientAxios from '../../../config/configAxios'
  
  export default NextAuth({
      providers: [
          Providers.Credentials({
              async authorize(credentials) {
                  try {
                      const login = await clientAxios.post('/api/login', {
                          username: credentials.username,
                          password: credentials.password,
                          is_master: credentials.is_master
                      })
  
  
                      const info = login.data.data.user
                      const token = {
                          accessToken: login.data.data.access_token,
                          expiresIn: login.data.data.expires_in,
                          refreshToken: login.data.data.refresh_token
                      }
                      // I can see cookies here
                      const cookies = login.headers['set-cookie']
  
                      return { info, token, cookies }
                  } catch (error) {
                      console.log(error)
                      throw (Error(error.response.data.M))
                  }
              }
          })
      ],
      callbacks: {
          async jwt(token, user, account, profile, isNewUser) {
              if (token) {
                 // Here cookies are set but only in server side
                 clientAxios.defaults.headers.common['Cookie'] = token.cookies
              }
              if (user) {
                  token = {
                      user: user.info,
                      ...user.token,
                  }
              }
  
              return token
          },
          async session(session, token) {
              // Add property to session, like an access_token from a provider.
              session.user = token.user
              session.accessToken = token.accessToken
              session.refreshToken = token.refreshToken
  
              return session
          }
      },
      session: {
          jwt: true
      }
  })
  </code></pre>
  <p>my axios config file</p>
  <pre class="lang-js prettyprint-override"><code>import axios from 'axios';
  
  const clientAxios = axios.create({
  
      baseURL: process.env.backendURL,
      withCredentials: true,
      headers:{
          'Accept' : 'application/json',
          'Content-Type' : 'application/json'
      }
  
  });
  
  export default clientAxios;
  </code></pre>
  <p>a page component</p>
  <pre class="lang-js prettyprint-override"><code>import { getSession } from &quot;next-auth/client&quot;;
  import clientAxios from &quot;../../../config/configAxios&quot;;
  import { useEffect } from &quot;react&quot;
  
  export default function PageOne (props) {
      useEffect(async () =&gt; {
        // This request fails, cookies are not sent
        const response = await clientAxios.get('/api/info');
      }, [])
  
      return (
          &lt;div&gt;
             &lt;h1&gt;Hello World!&lt;/h1&gt;
          &lt;/div&gt;
      )
  }
  
  export async function getServerSideProps (context) {
      const session = await getSession(context)
  
      if (!session) {
          return {
              redirect: {
                  destination: '/login',
                  permanent: false
              }
          }
      }
  
      // This request works
      const response = await clientAxios.get('/api/info');
      
      return {
          props: {
              session,
              info: response.data
          }
      }
  }
  
  </code></pre>