Skip to content

Commit

Permalink
feat: add getConnectedPubkey function to @joyid/nostr
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jul 12, 2024
1 parent 2e2e20c commit 7c06ed5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/happy-cats-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@joyid/nostr': minor
---

feat: add `getConnectedPubkey` function
19 changes: 18 additions & 1 deletion packages/nostr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,24 @@ const buildSignEventUrl = (event: UnsignedEvent): string => {

export const STORAGE_KEY = 'joyid:nostr::pubkey'

async function getPublicKey(): Promise<string> {
export const getConnectedPubkey = (): string | null => {
if (
typeof window !== 'undefined' &&
window.localStorage &&
typeof window.localStorage.getItem === 'function'
) {
return window.localStorage.getItem(STORAGE_KEY)
}
return null
}

async function getPublicKey(forceReconnected = true): Promise<string> {
if (!forceReconnected) {
const connectedPk = getConnectedPubkey()
if (connectedPk != null) {
return connectedPk
}
}
const res = await authWithPopup({
redirectURL: location.href,
requestNetwork: 'nostr',
Expand Down

0 comments on commit 7c06ed5

Please sign in to comment.