You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
941 B
36 lines
941 B
import { Controller } from '@hotwired/stimulus'; |
|
import { getComponent } from '@symfony/ux-live-component'; |
|
|
|
export default class extends Controller { |
|
async initialize() { |
|
this.component = await getComponent(this.element); |
|
} |
|
async loginAct() { |
|
const tags = [ |
|
['u', window.location.origin + '/login'], |
|
['method', 'POST'] |
|
] |
|
const ev = { |
|
created_at: Math.floor(Date.now()/1000), |
|
kind: 27235, |
|
tags: tags, |
|
content: '' |
|
} |
|
|
|
const signed = await window.nostr.signEvent(ev); |
|
// base64 encode and send as Auth header |
|
const result = await fetch('/login', { |
|
method: 'POST', |
|
credentials: 'same-origin', |
|
headers: { |
|
'Authorization': 'Nostr ' + btoa(JSON.stringify(signed)) |
|
} |
|
}).then(response => { |
|
if (!response.ok) return false; |
|
return 'Authentication Successful'; |
|
}) |
|
if (!!result) { |
|
this.component.render(); |
|
} |
|
} |
|
}
|
|
|