I have an Express server that right now signs into Supabase. The authentication is successful as when I print data
it gives me the user and session information. But when I try to retrieve the user or session information, it's just null. In the below code, event
becomes INITIAL_SESSION, session
becomes null, and user
also becomes null. I also don't really understand how Supabase's sessions work. I would gladly appreciate if anyone could shed some light on this.
app.post("/login", async(req, res) => {
const {data, error} = await supabase.auth.signInWithPassword({
email: req.body.email,
password: req.body.password
})
await supabase.auth.onAuthStateChange((event, session) => {
console.log(event, session);
})
if (error) {
console.log(error);
res.status(401).send("Email/password combination is wrong.");
}
else {
const { data: { user } } = await supabase.auth.getUser();
console.log(user);
res.status(202).send("Login successful.");
}
})