1. Go to this page and download the library: Download innis/nostr-sign-in 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/ */
innis / nostr-sign-in example snippets
final readonly class ProvisionOnFirstSignIn
{
public function __construct(private MemberStoreInterface $members) {}
#[AsEventListener]
public function __invoke(LoginSuccessEvent $event): void
{
$this->members->ensureExists($event->getUser()->getUserIdentifier());
}
}
final readonly class SqliteRoleAssigner implements RoleAssignerInterface
{
public function __construct(private PDO $connection) {}
#[Override]
public function rolesFor(PublicKey $pubkey): array
{
$statement = $this->connection->prepare('SELECT is_admin, is_editor FROM members WHERE pubkey = ?');
$statement->execute([$pubkey->toHex()]);
$row = $statement->fetch();
return [
'ROLE_USER',
...(false !== $row && $row['is_admin'] ? ['ROLE_ADMIN'] : []),
...(false !== $row && $row['is_editor'] ? ['ROLE_EDITOR'] : []),
];
}
}
sh
php examples/sign_in_round_trip.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.