login stuff
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
<script lang='ts'>
|
<!-- ndk-svelte-components/LoginDropdown.svelte -->
|
||||||
|
<script lang="ts">
|
||||||
import { ndk } from '$lib/stores/nostr';
|
import { ndk } from '$lib/stores/nostr';
|
||||||
|
import Nip07Button from './LoginModal/Nip07Button.svelte';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !$ndk.signer}
|
{#if !$ndk.signer}
|
||||||
|
|||||||
9
src/lib/components/LoginModal/CollapsableDropdown.svelte
Normal file
9
src/lib/components/LoginModal/CollapsableDropdown.svelte
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<!--lib/components/CollapsableDropdown.svelte-->
|
||||||
|
<script lang="ts">
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="dropdown">
|
||||||
|
<div class="dropdown-trigger">
|
||||||
|
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu"> </button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
18
src/lib/components/LoginModal/Modal.svelte
Normal file
18
src/lib/components/LoginModal/Modal.svelte
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let active = false;
|
||||||
|
|
||||||
|
function closeDialog() {
|
||||||
|
active = !active;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="modal" class:is-active={active}>
|
||||||
|
<div class="modal-background"></div>
|
||||||
|
<div class="modal-card">
|
||||||
|
<header class="modal-card-head">
|
||||||
|
<p class="modal-card-title">Login</p>
|
||||||
|
<button class="delete" aria-label="close" on:click={closeDialog}></button>
|
||||||
|
</header>
|
||||||
|
<section class="modal-card-body"></section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
32
src/lib/components/LoginModal/Nip07Button.svelte
Normal file
32
src/lib/components/LoginModal/Nip07Button.svelte
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { ndk } from '$lib/stores/nostr';
|
||||||
|
import { login } from '$lib/utils/login';
|
||||||
|
import { currentUser } from '$lib/store';
|
||||||
|
|
||||||
|
let noNip07: boolean;
|
||||||
|
|
||||||
|
$: noNip07 = !window.nostr;
|
||||||
|
|
||||||
|
async function nip07Login() {
|
||||||
|
const user = await login($ndk, undefined, 'nip07');
|
||||||
|
if (!user) alert('Nip07 Login Failed');
|
||||||
|
else {
|
||||||
|
$currentUser = user;
|
||||||
|
localStorage.setItem('nostr-key-method', 'nip07');
|
||||||
|
localStorage.setItem('nostr-target-npub', $currentUser.npub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if noNip07}
|
||||||
|
<div class="alert">
|
||||||
|
<span>No Nostr extension in your browser</span>
|
||||||
|
<div class="hidden">
|
||||||
|
<button class="button is-small">Need Help?</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<button on:click={nip07Login}>
|
||||||
|
<span>Use Browser Extension</span>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import {} from '@nostr-dev-kit/ndk-svelte-components';
|
||||||
import Avatar from '$lib/components/Avatar.svelte';
|
import Avatar from '$lib/components/Avatar.svelte';
|
||||||
import { ndk } from '$lib/stores/nostr';
|
import { ndk } from '$lib/stores/nostr';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import NavBar from '$lib/components/NavBar.svelte';
|
import NavBar from '$lib/components/NavBar.svelte';
|
||||||
|
import LoginModal from '$lib/components/LoginModal/Modal.svelte';
|
||||||
import { ndk } from '$lib/stores/nostr';
|
import { ndk } from '$lib/stores/nostr';
|
||||||
import { NDKNip07Signer } from '@nostr-dev-kit/ndk';
|
import { NDKNip07Signer } from '@nostr-dev-kit/ndk';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let modalActive = false;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await signIn();
|
await signIn();
|
||||||
});
|
});
|
||||||
|
|
||||||
async function signIn() {
|
async function signIn() {
|
||||||
|
modalActive = !modalActive;
|
||||||
console.debug('signIn called');
|
console.debug('signIn called');
|
||||||
let signer;
|
let signer;
|
||||||
try {
|
try {
|
||||||
@@ -35,3 +39,4 @@
|
|||||||
|
|
||||||
<NavBar on:signin={signIn} />
|
<NavBar on:signin={signIn} />
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
|
<LoginModal active={modalActive} />
|
||||||
|
|||||||
Reference in New Issue
Block a user