import {
createClient
} from '@supabase/supabase-js';
export default async function authenticateUserWithSupabase({
email,
password,
supabaseUrl,
supabaseKey
}) {
// Check for the existence of URL and Key, required for connecting to Supabase
if (!supabaseUrl || !supabaseKey) {
throw new Error('Supabase URL and Key must be provided.');
}
const supabase = createClient(supabaseUrl, supabaseKey);
try {
// Use Supabase client's auth.signIn() method to authenticate user credentials
const {
user,
session,
error
} = await supabase.auth.signIn({
email: email,
password: password
});
if (error) {
// Return an object with the error message to maintain security
return {
error: error.message
};
}
// If authentication is successful, return the session object
return {
session: session
};
} catch (error) {
// In a real-world scenario, you might not want to throw or return the error
// directly as it can contain sensitive details. For example:
// return { error: 'An unexpected error occurred.' };
throw error; // Uncomment the above line and comment this line for production use
}
}
import {
createClient
} from '@supabase/supabase-js';
export default async function authenticateUserWithSupabase({
email,
password,
supabaseUrl,
supabaseKey
}) {
// Check for the existence of URL and Key, required for connecting to Supabase
if (!supabaseUrl || !supabaseKey) {
throw new Error('Supabase URL and Key must be provided.');
}
const supabase = createClient(supabaseUrl, supabaseKey);
try {
// Use Supabase client's auth.signIn() method to authenticate user credentials
const {
user,
session,
error
} = await supabase.auth.signIn({
email: email,
password: password
});
if (error) {
// Return an object with the error message to maintain security
return {
error: error.message
};
}
// If authentication is successful, return the session object
return {
session: session
};
} catch (error) {
// In a real-world scenario, you might not want to throw or return the error
// directly as it can contain sensitive details. For example:
// return { error: 'An unexpected error occurred.' };
throw error; // Uncomment the above line and comment this line for production use
}
}