James singh
05/26/2023, 6:42 PMjs
supabase.auth.onAuthStateChange(async (event) => {
if (!event) return;
if (event === 'SIGNED_IN') {
console.log('User signed in'); //this spam in console multiple times without load page
} else return
});
Cedric
05/26/2023, 6:48 PMfunction handleAuthStateChange() {
fetchCurrentUser()
backbase.auth.offAuthStateChange(handleAuthStateChange);
}
backbase.auth.onAuthStateChange(handleAuthStateChange);
const fetchCurrentUser = async () => {
const { data: { user }, error } = await supabase.auth.getUser()
if (error) {
setFetchUserError('could not fetch user')
setCurrentUser(null)
console.log(error)
}
if (user) {
setCurrentUser(user || [])
setFetchUserError(null)
}
console.log("SIGNED IN")
}
It's far from perfect and really weird because it constantly throws an error that offauthstatechange isnt a function, yet it still functions like offauthstatechange is a function and the line does its job.
(Feel free to ignore this because this might hinder you more than help.)James singh
05/26/2023, 6:56 PMCedric
05/26/2023, 7:05 PM