<?php

if ( isset($_GET['all']) && $_GET['all'] == 1 ) {
    $db->delete('auth_token', ['userId' => $user['id']]);
    $message = 'Logged out all devices';
} else {
    $db->delete('auth_token', ['selector' => $selector, 'token' => hash('sha256', $validator), 'userId' => $user['id']]);
    $message = 'Logged out';
}

unset($_COOKIE['btbLogin']);
setcookie('btbLogin', '', time()-3600, '/clients', URL_COOKIES);

session_start();
$_SESSION['error'] = $message;

header('Location: '.URL_APP_LOGIN);
exit;