stnmonroe
04/18/2022, 4:30 AMJWT Expired
if I'm using the app for over an hour. This is the hook being used to attempt to update the user credentials as needed, but it doesn't work. Am I doing something wrong?
js
import { supabase } from '@root/services/supabase';
import { useSignIn } from '@root/api/auth/mutations';
import { useAuthState } from '@root/state/useAuthState';
import { useMount } from 'react-use';
export const useUpdateOnAuthStateChange = () => {
const { session: localSession, setSession, clearSession } = useAuthState();
const { mutate: signIn } = useSignIn({
onError: (error) => console.error(error),
});
useMount(() => {
if (localSession?.refresh_token) {
signIn({ refreshToken: localSession.refresh_token });
}
});
useMount(() => {
setSession(supabase.auth.session());
supabase.auth.onAuthStateChange((_event, session) => {
console.log('_event :>> ', _event);
console.log('session :>> ', session);
if (!!session) {
setSession(session);
} else {
clearSession();
}
});
window.onstorage = (e) => {
if (e.key === 'supabase.auth.token') {
const newSession = JSON.parse(e.newValue);
setSession(newSession?.currentSession);
}
};
});
};
Needle
04/18/2022, 4:30 AM/title
command!
We have solved your problem?
Click the button below to archive it.stnmonroe
04/18/2022, 4:33 AMbarry
04/18/2022, 9:19 AMNeedle
04/18/2022, 9:19 AMbarry
04/18/2022, 9:19 AMstnmonroe
04/18/2022, 3:45 PMuseMount
is a useEffect
without a dependency array. When developing, you should use things that promote intentionality. As a team grows, someone may add a dependency to a useEffect
not understanding that the intention was always to be a useMount
. That is why.
Anyway, with Firebase I've never had an issue with this, but with Supabase it's consistent. Any idea what I'm doing wrong?stnmonroe
04/18/2022, 3:48 PMrefresh_token
in this way? It originally wasn't there, but was added in an attempt to debug.
How do I auto refresh the user session when the token expires without having to refresh the entire page?stnmonroe
04/18/2022, 3:48 PMstnmonroe
04/19/2022, 3:59 PM