I built an auth function that looks like this:
const handleLogin = async (type) => {
const { user, error } =
type === "LOGIN"
? await supabase.auth.signIn({ email, password })
: await supabase.auth.signUp({ email, password });
if (error) {
alert(error);
} else if (!user && !error) {
alert("An email has been sent to you for verification!");
}
};
Fetching the jwt and getting the user:
useEffect(() => {
async () => {
const jwt = await AsyncStorage.getItem("user");
const currentUser = supabase.auth.api.getUser(jwt)
console.log(currentUser)
}
const session = supabase.auth.session();
setUser(session?.user ?? null);
const { data: authListener } = supabase.auth.onAuthStateChange(
async (event, session) => {
const currentUser = session?.user;
await AsyncStorage.setItem("user", session.access_token);
console.log(await AsyncStorage.getItem("user"));
setUser(currentUser ?? null);
}
);
return () => {
authListener?.unsubscribe();
};
}, [user]);
but I can't seem to find a way to keep the user logged in inside the app. everytime it restarts the user needs to login again.
Any ideas? Thanks in advance!