rafaelwendel / phpsupabase

PHP Client to use Supabase
MIT License
187 stars 17 forks source link

I need create two supabase services, for auth and other for consume? #18

Closed Codelaby closed 1 year ago

Codelaby commented 1 year ago
define('SUPABASE_URL', 'https://id-project.supabase.co/');
define('SUPABASE_KEY', 'apikeysupabase...');

$serviceAuth = new PHPSupabase\Service(
    SUPABASE_KEY, 
    SUPABASE_URL . 'auth/v1/'
);

$auth = $serviceAuth->createAuth();

try{
    $auth->signInWithEmailAndPassword('testuser@gmail.com', '1234');
    $data = $auth->data(); // get the returned data generated by request

    if(isset($data->access_token)){
        $userData = $data->user; //get the user data
        echo 'Login successfully for user ' . $userData->email;

        //save the $data->access_token in Session, Cookie or other for future requests.
    }
}
catch(Exception $e){
    print_r($e);
}

If the url route is set with supabase/auth/v1 then the queries cannot be performed. I nedd create another service with resource consumption url with supabase.co/rest/v1

$service = new PHPSupabase\Service(
    SUPABASE_KEY, 
    SUPABASE_URL . 'rest/v1/'
);

$db = $service->initializeDatabase('lightprice', 'id');

Or is it working correctly as it should be used?

rafaelwendel commented 1 year ago

Hello.

Yes. As they are two distinct activities (auth and database), it is necessary to create the instances separately.

However, it is something I intend to improve in future versions.

Best regwards =)

rafaelwendel commented 1 year ago

hi @Codelaby

The version 0.0.5 (available) solve you demand. Now it is possible use the same service instance to create auth or database/querybuilder objects.

=)