1. Go to this page and download the library: Download rafaelwendel/phpsupabase library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rafaelwendel / phpsupabase example snippets
ice = new PHPSupabase\Service(
"YOUR_API_KEY",
"https://aaabbbccc.supabase.co"
);
//In versions 0.0.4 or earlier it is necessary to set the suffix
$service = new PHPSupabase\Service(
"YOUR_API_KEY",
"https://aaabbbccc.supabase.co/auth/v1"// or https://aaabbbccc.supabase.co/rest/v1
);
$auth = $service->createAuth();
$auth = $service->createAuth();
try{
$auth->createUserWithEmailAndPassword('newuser@email.com', 'NewUserPassword');
$data = $auth->data(); // get the returned data generated by requestecho'User has been created! A confirmation link has been sent to the '. $data->email;
}
catch(Exception $e){
echo $auth->getError();
}
$auth = $service->createAuth();
try{
$auth->signInWithEmailAndPassword('user@email.com', 'UserPassword');
$data = $auth->data(); // get the returned data generated by requestif(isset($data->access_token)){
$userData = $data->user; //get the user dataecho'Login successfully for user ' . $userData->email;
//save the $data->access_token in Session, Cookie or other for future requests.
}
}
catch(Exception $e){
echo $auth->getError();
}
$auth = $service->createAuth();
$bearerToken = 'THE_ACCESS_TOKEN';
try{
$data = $auth->getUser($bearerToken);
print_r($data); // show all user data returned
}
catch(Exception $e){
echo $auth->getError();
}
$auth = $service->createAuth();
$bearerToken = 'THE_ACCESS_TOKEN';
$newUserMetaData = [
'first_name' => 'Michael',
'last_name' => 'Jordan'
];
try{
//the parameters 2 (email) and 3(password) are null because this data will not be changed
$data = $auth->updateUser($bearerToken, null, null, $newUserMetaData);
print_r($data); // show all user data returned
}
catch(Exception $e){
echo $auth->getError();
}