Thankyou mate! Writing it down before I forget wha...
# javascript
s
Thankyou mate! Writing it down before I forget what we did. Created /api/auth
Copy code
import supabase from '@utils/supabase';

const AuthCookie = async (req, res) => {
  supabase.auth.api.setAuthCookie(req, res);
};

export default AuthCookie;
Updated my auth hook to include:
Copy code
----other stuff
async function handleAuthChange(event, session) {
  await fetch('/api/auth', {
    method: 'POST',
    headers: new Headers({ 'Content-Type': 'application/json' }),
    credentials: 'same-origin',
    body: JSON.stringify({ event, session })
  });
}

----within context provider
const { data: authListener } = supabase.auth.onAuthStateChange(
      async (event, session) => {
        setSession(session);
        handleAuthChange(event, session);  <---- this
        setUser(session?.user ?? false);
      }
    );
Then on my /api/settings I can call
supabase.auth.setAuth(req.cookies['sb:token']);
which passes the user details back to the server 🙂 Can the setAuth call go in the auth hook somewhere? 🤔
NextJS api passing user back to server
s
This was a really good pairing session
s
Yes it was, thanks again mate! I'd love for someone that's proficient at react to suggest where I should be getting the cookie. Or confirm that doing it in every API call is the right way to go...