Support Aegis URL scheme for NIP-46 login (#161)
Co-authored-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com> Co-committed-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
This commit was merged in pull request #161.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {Capacitor} from "@capacitor/core"
|
||||||
import {onMount, onDestroy} from "svelte"
|
import {onMount, onDestroy} from "svelte"
|
||||||
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
||||||
import {Nip46Broker} from "@welshman/signer"
|
import {Nip46Broker} from "@welshman/signer"
|
||||||
@@ -103,10 +104,16 @@
|
|||||||
mode = "connect"
|
mode = "connect"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openSigner = () => {
|
||||||
|
controller.launchSigner()
|
||||||
|
}
|
||||||
|
|
||||||
const selectBunker = () => {
|
const selectBunker = () => {
|
||||||
mode = "bunker"
|
mode = "bunker"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isIos = Capacitor.getPlatform() === "ios"
|
||||||
|
|
||||||
let mode: string = $state("bunker")
|
let mode: string = $state("bunker")
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -138,6 +145,9 @@
|
|||||||
<BunkerUrl {controller} />
|
<BunkerUrl {controller} />
|
||||||
<Button class="btn {$bunker ? 'btn-neutral' : 'btn-primary'}" onclick={selectConnect}
|
<Button class="btn {$bunker ? 'btn-neutral' : 'btn-primary'}" onclick={selectConnect}
|
||||||
>Log in with a QR code instead</Button>
|
>Log in with a QR code instead</Button>
|
||||||
|
{#if isIos}
|
||||||
|
<Button class="btn btn-neutral" onclick={openSigner}>Open in Signer</Button>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
|
|||||||
+33
-1
@@ -1,4 +1,4 @@
|
|||||||
import {writable} from "svelte/store"
|
import {get, writable} from "svelte/store"
|
||||||
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
import type {Nip46ResponseWithResult} from "@welshman/signer"
|
||||||
import {Nip46Broker} from "@welshman/signer"
|
import {Nip46Broker} from "@welshman/signer"
|
||||||
import {makeSecret} from "@welshman/util"
|
import {makeSecret} from "@welshman/util"
|
||||||
@@ -11,6 +11,22 @@ import {
|
|||||||
} from "@app/core/state"
|
} from "@app/core/state"
|
||||||
import {pushToast} from "@app/util/toast"
|
import {pushToast} from "@app/util/toast"
|
||||||
|
|
||||||
|
const APP_SCHEME = "social.flotilla"
|
||||||
|
|
||||||
|
const makeSignerCallbackUrl = (path: string) => `${APP_SCHEME}://x-callback-url/${path}`
|
||||||
|
|
||||||
|
const makeSignerLaunchUrl = (nostrconnectUrl: string) => {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
method: "connect",
|
||||||
|
nostrconnect: nostrconnectUrl,
|
||||||
|
"x-source": APP_SCHEME,
|
||||||
|
"x-success": makeSignerCallbackUrl("authSuccess"),
|
||||||
|
"x-error": makeSignerCallbackUrl("authError"),
|
||||||
|
})
|
||||||
|
|
||||||
|
return `nostrsigner://x-callback-url/auth/nip46?${params.toString()}`
|
||||||
|
}
|
||||||
|
|
||||||
export class Nip46Controller {
|
export class Nip46Controller {
|
||||||
url = writable("")
|
url = writable("")
|
||||||
bunker = writable("")
|
bunker = writable("")
|
||||||
@@ -54,6 +70,22 @@ export class Nip46Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
launchSigner() {
|
||||||
|
const nostrconnectUrl = get(this.url)
|
||||||
|
const signerUrl = nostrconnectUrl && makeSignerLaunchUrl(nostrconnectUrl)
|
||||||
|
|
||||||
|
if (!signerUrl) {
|
||||||
|
pushToast({
|
||||||
|
theme: "error",
|
||||||
|
message: "Unable to open signer app right now. Please try again.",
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.href = signerUrl
|
||||||
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
this.broker.cleanup()
|
this.broker.cleanup()
|
||||||
this.abortController.abort()
|
this.abortController.abort()
|
||||||
|
|||||||
@@ -78,6 +78,21 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (url.host === "x-callback-url") {
|
||||||
|
if (url.pathname === "/authError") {
|
||||||
|
const errorMessage = url.searchParams.get("errorMessage")
|
||||||
|
|
||||||
|
pushToast({
|
||||||
|
theme: "error",
|
||||||
|
message: errorMessage || "Signer authorization failed.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (["/authSuccess", "/authError"].includes(url.pathname)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const target = `${url.pathname}${url.search}${url.hash}`
|
const target = `${url.pathname}${url.search}${url.hash}`
|
||||||
goto(target, {replaceState: false, noScroll: false})
|
goto(target, {replaceState: false, noScroll: false})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user