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.
<?php
require_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('[email protected]', 'NewUserPassword');
$data = $auth->data(); // get the returned data generated by request
echo '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('[email protected]', 'UserPassword');
$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){
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();
}
$service = new PHPSupabase\Service(
"YOUR_SERVICE_ROLE_KEY",
"https://aaabbbccc.supabase.co"
);
$authAdmin = $service->createAuthAdmin();
// List users (paginated)
$authAdmin->listUsers(1, 50);
$users = $authAdmin->data()->users;
// Get a single user
$authAdmin->getUser('user-uuid');
// Update a user — any subset of attributes can be passed
$authAdmin->updateUser('user-uuid', [
'email' => '[email protected]',
'password' => 'new-password',
'user_metadata' => ['role' => 'editor'],
'ban_duration' => '24h', // ban (use 'none' to unban)
]);
// Delete a user
$authAdmin->deleteUser('user-uuid');