updateUser error
Hey! I’m having an issue with supabase.auth.updateUser(). Sometimes when I click my update button, I get an error and no /user request is sent in the auth logs (And unfortunately I don't access to the log in the app). If I click again, it works — it's inconsistent and hard to reproduce. Any idea what could cause this?
7 Replies
Seems like something in your code if it is not sending to Supabase.
Maybe talk about your framework/codebase and show some relevant code around this.
Not having a log in an app makes it pretty tough to debug the code doesn't it?
If you don't have a user session it would error to your app and not send it out I believe.

And my AuthContext :
import {
PropsWithChildren,
createContext,
useContext,
useEffect,
useState, useMemo,
} from 'react';
import { supabase } from '../lib/supabase';
import { Session, User } from '@supabase/supabase-js';
type AuthContext = {
user: User | null;
session: Session | null;
};
const AuthContext = createContext<AuthContext>({
user: null,
session: null,
});
export const AuthProvider =({ children }: PropsWithChildren) => {
const [session, setSession] = useState<Session | null>(null);
useEffect(() => {
const subscription = supabase.auth.onAuthStateChange((_event, session) => {
setSession(session);
});
return () => {
console.log("Unsubscribing for Auth status change...")
subscription.data.subscription.unsubscribe();
};
}, []);
const value = useMemo(
() => ({
user: session?.user ?? null,
session,
}),
[session]
);
return (
<AuthContext.Provider
value={value}
>
{children}
</AuthContext.Provider>
);
}
export const useAuth = () => useContext(AuthContext);
I just move the line 'const {user} = useAuth()' in the handlePress function to show you where the user object come from, but in reality it is not in the handlePress function, it is at the top with the definition of the component states
It's likely
user is null when you call handlePress the first time and then it's not null the next time.Thank you for yours answers, I add some details
If user is null, I don't display any Toast erro in the UI.
I only display an Toast error if an error is thrown.
And in my case, I have a Toast error so it comes from updateUser function, but i don't know why
Log the actual
error variable to see if there is any errors in it. Also without seeing the rest of your code what guarantees you that the Toast error is coming from the handlePress function?Yes thank you I will add some log for the future. The Toast is directly linked to this function, so 100% come from this function