@konemono/nostr-login 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -123,8 +123,12 @@ export class AmberDirectSigner implements Signer {
123
123
  }
124
124
 
125
125
  public generateUrl(content: string, type: string, id: string, pubkey?: string): string {
126
- const callbackUrl = window.location.href.split('#')[0].split('?')[0];
126
+ const baseUrl = window.location.href.split('#')[0].split('?')[0];
127
127
  const encodedContent = encodeURIComponent(content || '');
128
+
129
+ // callbackUrl にはベースURLに結果パラメータのプレースホルダーを含める
130
+ // Amberが戻ってくる時に ?event=<result> が追加される
131
+ const callbackUrl = `${baseUrl}?event={result}`;
128
132
  const encodedCallback = encodeURIComponent(callbackUrl);
129
133
 
130
134
  localStorage.setItem('amber_last_type', type);
@@ -141,18 +141,20 @@ class AuthNostrService extends EventEmitter implements Signer {
141
141
  const resolved = AmberDirectSigner.resolvePending(response.id, response.type, response.result);
142
142
  if (resolved) {
143
143
  console.log('[AuthNostrService] Resolved pending Amber promise');
144
- }
145
-
146
- if (response.type === 'get_public_key' || response.type.includes('pub')) {
147
- const info: Info = {
148
- pubkey: response.result,
149
- name: nip19.npubEncode(response.result),
150
- authMethod: 'amber' as any,
151
- relays: [],
152
- signerPubkey: '',
153
- };
154
- console.log('[AuthNostrService] Amber login success:', info);
155
- this.onAuth('login', info);
144
+ } else {
145
+ // resolvePendingが失敗した場合、ページリロード時などは二度目のログイン
146
+ console.log('[AuthNostrService] No pending promise, handling as second login');
147
+ if (response.type === 'get_public_key' || response.type.includes('pub')) {
148
+ const info: Info = {
149
+ pubkey: response.result,
150
+ name: nip19.npubEncode(response.result),
151
+ authMethod: 'amber' as any,
152
+ relays: [],
153
+ signerPubkey: '',
154
+ };
155
+ console.log('[AuthNostrService] Amber login success:', info);
156
+ this.onAuth('login', info);
157
+ }
156
158
  }
157
159
 
158
160
  // URLクリーンアップをより徹底的に