Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Dolu89/nostr-one
https://github.com/Dolu89/nostr-one
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/Dolu89/nostr-one
- Owner: Dolu89
- License: mit
- Created: 2023-07-17T17:25:27.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-07-18T17:08:27.000Z (over 1 year ago)
- Last Synced: 2024-12-01T13:42:18.178Z (22 days ago)
- Language: Vue
- Homepage: https://nostr-one.dolu.dev
- Size: 19.5 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ``
The `` custom element is a reusable web component that provides a simple way to integrate with the Nostr [NIP 98](https://github.com/nostr-protocol/nips/blob/master/98.md) HTTP Auth. It can be used in any web project that supports custom elements.
## Installation
```bash
npm install nostr-one
``````js
import "nostr-one";
```## Usage
To use the `` custom element in your web project, you can include it in your HTML file and configure it using attributes:
```html
```
In this example, we configure the component using the `login-url` and `http-method` attributes. These attributes correspond to the options you can pass to the `NostrOne` class constructor.
You can also configure the component using JavaScript:
```html
const nostrOne = document.getElementById('nostr-one');
nostrOne.loginUrl = 'https://example.com/login';
nostrOne.httpMethod = 'post';
nostrOne.onSuccess = function(data) {
console.log('Success:', data);
};
nostrOne.onError = function(error) {
console.error('Error:', error);
};
nostrOne.onClick = function(eventB64) {
console.log('Click:', eventB64);
};```
In this example, we use JavaScript to configure the component after it has been added to the DOM. We access the component using its `id` attribute and set its properties using JavaScript.
## API
The `` custom element has the following properties:
### `loginUrl` required
The URL to use for the Nostr API login endpoint.
### `httpMethod`
The HTTP method to use for the Nostr API login request.
Accepts `get` and `post`
Default to `post`### `onSuccess`
A callback function to be called when the Nostr API login request succeeds. The function is passed the response data as an argument.
### `onError`
A callback function to be called when the Nostr API login request fails. The function is passed the error object as an argument.
### `onClick`
⚠️ If used, the component will not send the HTTP request automatically.\
A callback function to be called when the user clicks on the component. The function is passed the event data as a base64-encoded string.## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.