-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
problem: user can only sign in with extension (#27)
- Loading branch information
Showing
9 changed files
with
467 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script lang="ts"> | ||
import * as Dialog from '$lib/components/ui/dialog'; | ||
import { Input } from '@components/ui/input'; | ||
import { Button } from '@components/ui/button'; | ||
import { ndk } from '$lib/ndk/ndk'; | ||
import { connectToBunker } from '$lib/ndk/login'; | ||
import { currentPubkey } from '$lib/stores/user'; | ||
$: isLoading = false; | ||
let nip05 = ''; | ||
async function handleLogin() { | ||
isLoading = true; | ||
try { | ||
const signer = await connectToBunker(nip05); | ||
$currentPubkey = (await signer.user()).pubkey; | ||
$ndk.signer = signer; | ||
} catch (error) { | ||
console.error('Login failed:', error); | ||
} finally { | ||
isLoading = false; | ||
} | ||
} | ||
</script> | ||
|
||
<Dialog.Root> | ||
<Dialog.Trigger class="w-full"> | ||
<Button class="w-full">Nostr Address</Button> | ||
</Dialog.Trigger> | ||
<Dialog.Content> | ||
<Dialog.Header> | ||
<Dialog.Title>Login with Nostr Address</Dialog.Title> | ||
</Dialog.Header> | ||
<form on:submit|preventDefault={handleLogin}> | ||
<div class="grid gap-4 py-4"> | ||
<div class="grid grid-cols-4 items-center gap-4"> | ||
<label for="bunker-id" class="text-right"> Nostr Address </label> | ||
<Input id="bunker-id" placeholder="user@provider" bind:value={nip05} class="col-span-3" /> | ||
</div> | ||
<p class="col-span-4 text-center text-sm text-gray-600"> | ||
Don't have a Nostr address? You can sign up for one at | ||
<a | ||
href="https://nsec.app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
class="text-blue-500 hover:underline">nsec.app</a | ||
>. | ||
</p> | ||
</div> | ||
<Dialog.Footer> | ||
<Button type="submit" disabled={isLoading}> | ||
{#if isLoading} | ||
Connecting to bunker... | ||
{:else} | ||
Connect | ||
{/if} | ||
</Button> | ||
</Dialog.Footer> | ||
</form> | ||
</Dialog.Content> | ||
</Dialog.Root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script lang="ts"> | ||
import { Button } from '$lib/components/ui/button/index.js'; | ||
import { Check, Copy } from 'lucide-svelte'; | ||
export let text; | ||
let copyed: boolean; | ||
</script> | ||
|
||
<Button | ||
on:click={() => { | ||
if (text && navigator.clipboard) { | ||
navigator.clipboard.writeText(text); | ||
copyed = true; | ||
setTimeout(() => { | ||
copyed = false; | ||
}, 2000); | ||
} | ||
}} | ||
> | ||
{#if copyed} | ||
<Check class="h-5 w-5" /> | ||
{:else} | ||
<Copy class="h-5 w-5" /> | ||
{/if} | ||
</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import { ndk } from '$lib/ndk/ndk'; | ||
import { Button } from '@/components/ui/button'; | ||
import * as Dialog from '$lib/components/ui/dialog'; | ||
import { NDKPrivateKeySigner } from '@nostr-dev-kit/ndk'; | ||
import { nip19 } from 'nostr-tools'; | ||
import CopyButton from './CopyButton.svelte'; | ||
import { Input } from '$lib/components/ui/input'; | ||
import { currentPubkey } from '$lib/stores/user'; | ||
let temporaryAccount: NDKPrivateKeySigner; | ||
let nsec: string; | ||
async function createTemporaryAccount() { | ||
temporaryAccount = NDKPrivateKeySigner.generate(); | ||
nsec = nip19.nsecEncode(temporaryAccount.privateKey!); | ||
console.log(nsec); | ||
} | ||
async function useTemporaryAccount() { | ||
$currentPubkey = (await temporaryAccount.user()).pubkey; | ||
$ndk.signer = temporaryAccount; | ||
localStorage.setItem('signed-in', 'nsec'); | ||
localStorage.setItem('signed-in-nsec', nsec); | ||
} | ||
</script> | ||
|
||
<Dialog.Root> | ||
<Dialog.Trigger class="w-full"> | ||
<Button on:click={createTemporaryAccount} class="w-full">Use Temporary Account</Button> | ||
</Dialog.Trigger> | ||
<Dialog.Content> | ||
<div class="space-y-6 py-4"> | ||
<p class="mb-4"> | ||
Your temporary account has been created. Please save the following private key (nsec) for | ||
future use: | ||
</p> | ||
<div class="mb-4 flex gap-2"> | ||
<Input bind:value={nsec} readonly /> | ||
<CopyButton text={nsec} /> | ||
</div> | ||
<p class="mb-6 text-sm text-gray-600"> | ||
Warning: Please store this private key in a secure location. If lost, you will not be able | ||
to access this account again. | ||
</p> | ||
<Button on:click={useTemporaryAccount} class="w-full"> | ||
I've Safely Stored the Private Key | ||
</Button> | ||
</div> | ||
</Dialog.Content> | ||
</Dialog.Root> |
Oops, something went wrong.