stibbs
07/29/2021, 12:57 PMimport supabase from '@utils/supabase';
const AuthCookie = async (req, res) => {
supabase.auth.api.setAuthCookie(req, res);
};
export default AuthCookie;
Updated my auth hook to include:
----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? 🤔stibbs
07/29/2021, 1:00 PMsilentworks
07/29/2021, 1:16 PMstibbs
07/30/2021, 12:41 AM