Reputation: 3
import { supabase } from "..//main";
document.getElementById('login-button').addEventListener('click', async function (event) { event.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
try {
const { user, session, error } = await supabase.auth.signInWithPassword({
email,
password,
});
if (error) {
console.error(error.message);
// Display an error message to the user (you can customize this part)
alert('Invalid email or password');
} else {
console.log('Login Successful:', user, session);
// Add a short delay to allow the authentication state to update
setTimeout(() => {
// Redirect to another page or perform other actions after successful login
window.location.href = 'home.html';
// Check the user status after the login attempt
console.log('User after login attempt:', supabase.auth.user);
}, 500); // You can adjust the delay time as needed
}
} catch (error) {
console.error('General Error:', error.message);
}
});
This my login logic for my CapacitorJS project. The login and signup is working as I can see in my supabase dashboard. But when I try checking in after logging in using this
// Check the user status after the login attempt console.log('User after login attempt:', supabase.auth.user);
It says undefined and I cannot continue with want I want to do.
Upvotes: 0
Views: 362
Reputation: 18670
Supabase auth does not have a user
property, so supabase.auth.user
is always undefined.
In order to see if you have a session or not, you can do the following:
const { data, error } = await supabase.auth.getSession()
console.log(`session: `, data)
Upvotes: 0